How can I catch jQuery AJAX errors? How can I catch jQuery AJAX errors? ajax ajax

How can I catch jQuery AJAX errors?


try this:

$.ajax({    url: remoteURL,    type: 'GET',    error: function (err) {        console.log("AJAX error in request: " + JSON.stringify(err, null, 2));    }}).always(function(jqXHR, textStatus) {    if (textStatus != "success") {        alert("Error: " + jqXHR.statusText);    }});

XHR Listener:

$.ajax({    url: remoteURL,    type: 'GET',    xhr: function(){        var xhr = new window.XMLHttpRequest();        xhr.addEventListener("error", function(evt){            alert("an error occured");        }, false);        xhr.addEventListener("abort", function(){            alert("cancelled");        }, false);        return xhr;    },    error: function (err) {        console.log("AJAX error in request: " + JSON.stringify(err, null, 2));    }});


You can use web developer console in google chrome. Press F12. And use Networks tab for checking response, And for JavaSvript and jQuery and Ajax errors you can use Console tab. :)

Try this by adding to your ajax function :

error: function(XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown);