Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine why a jQuery ajax $.post request wasn't successful?

Tags:

jquery

ajax

post

I'm trying to determine, based on the result of this call, if it was successful. The successFunction doesn't get called, so I'm assuming it was not. How do I know what went wrong?

xmlRequest = $.post("/url/file/", { 'id' : object.id }, successFunction, 'json');

Do I use the xmlRequest object?

like image 481
SeanDowney Avatar asked Dec 10 '22 23:12

SeanDowney


2 Answers

You can use:

$.ajax({
    url:"/url/file/",
    dataType:"json"
    data:{ 'id' : object.id }
    error:function(request){alert(request.statusText)}
    success:successFunction
})
like image 87
defrex Avatar answered Dec 13 '22 15:12

defrex


You could use the $.ajaxComplete() and/or $.ajaxError() methods to attach function to those events. I would also recommend using the Firefox browser with the Firebug pluging, you can get a lot of information about the requests and responses.

like image 20
palehorse Avatar answered Dec 13 '22 14:12

palehorse