admin管理员组文章数量:1399887
I have a problem with the following code.
var sendJson = (JSON.stringify(anda));
$.ajax({
url: 'sendMail.php',
type : "post",
data: sendJson,
success: function(data){
alert("Comanda dumneavoastra a fost trimisa");
}
});
Seems like data is not sent.... any idea why?
Ok... I know nothing is sent because I monitor requests with firebug. I get no errors, nothing in console. Checked if it is activated, it is.
I have a problem with the following code.
var sendJson = (JSON.stringify(anda));
$.ajax({
url: 'sendMail.php',
type : "post",
data: sendJson,
success: function(data){
alert("Comanda dumneavoastra a fost trimisa");
}
});
Seems like data is not sent.... any idea why?
Ok... I know nothing is sent because I monitor requests with firebug. I get no errors, nothing in console. Checked if it is activated, it is.
Share Improve this question edited Jun 22, 2012 at 15:56 zozo asked Jun 22, 2012 at 15:50 zozozozo 8,59219 gold badges83 silver badges141 bronze badges 10-
what errors are you getting? Add an
error
callback and will can get more info on the actual error.. – MilkyWayJoe Commented Jun 22, 2012 at 15:51 - That's the problem. No errors. – zozo Commented Jun 22, 2012 at 15:51
- Also, try using fiddler to see what requests are sent. www.fiddlertool. – BNL Commented Jun 22, 2012 at 15:52
- 3 Let's rephrase the question: what indications do you see that this is not working? – Jonathan M Commented Jun 22, 2012 at 15:52
- 2 K... added callback and found the problem. It was a bad uri... although I usualy got the bad uri from fbug also. Ty for help... post as answer so I can accept pls. – zozo Commented Jun 22, 2012 at 16:02
1 Answer
Reset to default 7Here's what I meant with my ment:
var sendJson = (JSON.stringify(anda));
$.ajax({
url: '/resource_url_goes_here',
type : 'POST',
data: sendJson,
success: function(data){
/* implementation goes here */
},
error: function(jqXHR, textStatus, errorThrown) {
/* implementation goes here */
}
});
Note that the ajax request has an error
callback now. All requests should have an error callback so you can easily identify when errors are happening (as you've seen, firebug doesn't catch everything).
Another thing that I find helpful sometimes is StatusCodes
:
$.ajax({
url: '/resource_url_goes_here',
type : 'POST',
data: sendJson,
statusCode: {
404: function() {
/*implementation for HTTP Status 404 (Not Found) goes here*/
},
401: function() {
/*implementation for HTTP Status 401 (Unauthorized) goes here*/
}
},
success: function(data){
/* implementation goes here */
},
error: function(jqXHR, textStatus, errorThrown) {
/* implementation goes here */
}
});
This will execute a function when a specific status code is returned by the server (404 and 401 in this snippet) and you can have a specific handler for the status codes you need. You can find more about this here.
本文标签: javascriptjquery ajax does not send requestStack Overflow
版权声明:本文标题:javascript - jquery ajax does not send request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744186515a2594314.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论