Reputation: 868
How to print exact error for given ajax snippet. Actually I am calling my .php script which returns the data fetched from database in json format. And while running this it shows me some error i.e alert box of error popups, so how to find exact error over here?
$.ajax({
type: "POST",
dataType: 'json',
// url: "store_locator.php",
url : "http://localhost/GoogleMaps/store_locator.php",
data: parameters,
success: function(msg) {
//alert(msg);
displayStores(msg);
},
error:function (xhr, ajaxOptions, thrownError){
alert("Error : "+thrownError);
}
});
Upvotes: 0
Views: 2372
Reputation: 13
you can check the "responseText" values of the first item of the error function so like error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText); } should show you the contents of the error
Upvotes: 0
Reputation: 1326
Sounds like you are trying to debug. So in order to do that these are some things you could try:
use
xhr.status
to check the status code returned by the server which will give you a clue as to what is going on. Status codes and meanings
then
xhr.responseText
may give you some additional info.
As mentioned in comments use the console to see network traffic and JavaScript errors - in IE or Chrome you can push F12 to bring up the developer tools.
To answer the question this JSFiddle shows how to handle the error response returned and get available details from it.
Upvotes: 1