The following piece of code, which calls a service using jQuery's getJSON, without the useJsonp
section, worked fine for me for a long time. Then, there was a need to support JSONP and the if (useJsonp)
condition was added. This also works fine, until the HTTP request fails. When I'm failing it (using Fiddler) with an 404 response, none of the callback (.done
nor .fail
is being called). When the request doesn't fail, I get to the .done
callback.
function getData(url){
var dfd = $.Deferred();
if (useJsonp) {
url += '&callback=?';
}
$.when($.getJSON(url))
.done(function (dataObj) {
if (!dataObj || dataObj.Status === 'failed') {
dfd.reject(dataObj);
}
else {
doSomething(dataObj);
dfd.resolve(dataObj);
}
})
.fail(function (jqXHR) {
dfd.reject(jqXHR);
});
return dfd.promise();
};
Why is that? What can I do to make the callbacks called?
Thanks