Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture the 500 error message using jquery?

How can i capture the 500 error message using jquery? I want to keep on checking for the 500 error message for sometime until it changes and time out after 50 sec.

I used the code below to try to capture and check the 500 error message but it doesnt seem to catch the 500 error message. I can see it in the firebug

$.ajax({
    statusCode: {
        500: function() {
            alert(" 500 data still loading");
            console.log('500 ');
        }
    }
}); 
like image 830
user244394 Avatar asked Nov 30 '12 04:11

user244394


2 Answers

Dispite the accepted answer mentioned by @Danny, you can also do this in newer versions of jQuery.

var xhr = $.ajax({
    url: "somewhere"
});

xhr.fail(function(xhr, textStatus, error) {
    // Error handling stuff here ...
});

See Deferred Object.

like image 75
Vicary Avatar answered Oct 16 '22 04:10

Vicary


Are you missing url in $.ajax like the one below

$.ajax({
    url: "/path to page",
    statusCode: {
        500: function() {
            alert(" 500 data still loading");
            console.log('500 ');
        }
    }
}); 
like image 33
Murali N Avatar answered Oct 16 '22 04:10

Murali N