javascript - jquery ajax does not send request - Stack Overflow

I have a problem with the following code.var sendJson = (JSON.stringify(anda));$.ajax({url: 'sendM

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
 |  Show 5 more ments

1 Answer 1

Reset to default 7

Here'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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744186515a4562229.html

相关推荐

  • javascript - jquery ajax does not send request - Stack Overflow

    I have a problem with the following code.var sendJson = (JSON.stringify(anda));$.ajax({url: 'sendM

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信