Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for 404 error status in jquery

I use this code to get some information from twitter via their api:

        $.ajax({
            url : apiUrl,
            cache : false,
            crossDomain: true,
            dataType: "jsonp",
            success : function(html) {
                // ...
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log(jqXHR);
            }
        });

However, if the apiUrl variable provides a correct url, this code work fine, e.i. the success object is executed, but if the url isn't correct, e.i. 404 error is returned from twitter, the error object is never executed. It doesn't log anything in console. How should I check for 404 error status in this case?

like image 551
King Julien Avatar asked Mar 02 '12 13:03

King Julien


1 Answers

From jQuery API ajax docs:

error option

Note: This handler is not called for cross-domain script and JSONP requests.

http://api.jquery.com/jQuery.ajax/

like image 98
charlietfl Avatar answered Sep 30 '22 07:09

charlietfl