How can I determine why a jQuery ajax $.post request wasn't successful?
Question
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?
Solution
You can use:
$.ajax({
url:"/url/file/",
dataType:"json"
data:{ 'id' : object.id }
error:function(request){alert(request.statusText)}
success:successFunction
})
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow