Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.getJSON().error() isn't being executed on 404 error

This is a brief outline of my code:

$.getJSON(json_url, function(data) {
    // application logic
}).error(function() {
    console.log("error");
});

The problem is that when the server returns a 404 error, it does not appear to be handled as there is no console.log() saying error, but there is a GET request failure with a code of 404 (Not Found) showing up in the console.

I am using jQuery 1.9.0.

Is there some simple error I am making?

like image 883
ixchi Avatar asked Oct 22 '22 19:10

ixchi


1 Answers

Due to the nature of JSONP requests, the error callback is not called for those.

From the docs:

When data is retrieved from remote servers (which is only possible using the script or jsonp data types), the error callbacks and global events will never be fired.

like image 105
Felix Kling Avatar answered Nov 02 '22 09:11

Felix Kling