Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery $.ajax throws js error when return header is 404

Tags:

jquery

I'm experiencing something odd here, that I don't recall ever running into. I'm doing a normal $.ajax call to my server (codeigniter backend) and if some resource isn't found, I'm returning some error message along with a 404 header. jQuery recognizes that an error has occurred and runs the proper error callbacks. The issue is that it also throws a js exception in the browser, so firebug will complain (or whatever js console the browser might be using). Is this a new behavior? I don't recall jquery throwing a js error when a 404 header is returned. Relevant code below:

$.extend({
    gallery: function (url, data) {
        //send a request to an arbitrary url with some data. Expects to
        //get json returned.
        return $.ajax(State.url + url, $.extend({
            dataType: 'json',
            type: 'post'
        }, data));
    }
}); 

Above is my global ajax function I use in my app. I've tried various flavors of an error functions in that function but to no avail, I always get a js error thrown in firebug. Any ideas? The actual js error I'm getting is:

NetworkError: 404 Not Found
like image 990
Greg Avatar asked Nov 05 '22 11:11

Greg


1 Answers

This is your console feature, not some jQuery gotcha. Try fiddling with your console options. Even Google Chrome tells that XHR failed or something like that.

P.S: Never used firebug. But it must be something in there only.

like image 93
Nishchay Sharma Avatar answered Nov 14 '22 23:11

Nishchay Sharma