Search code examples
javascriptjqueryajaxhttp-headershttp-status-code-403

jQuery doesn't seem to recognize a different string with an Ajax call statuscode 403


I am having a funny situation which I am not sure if it is my fault, or jQuery's fault, and therefore I would like to consult you guys.

Currently I am doing an Ajax call, which returns a 403 status code. But the string accompanying that 403 is different from the standard.

It returns 403 access denied but according to specification it should be 403 Forbidden.

I know how to get a 200 statuscode from the server, the question is more in how to handle this situation.

This is my Ajax jQuery code, and it does not get in any of the console.log() situations.

this.get = function(){
    var callUrl = self.url + "&limit=" + self.limit + "&page=" + self.page;
    callUrl += self.getFilterQuery();
    callUrl += "&callback=?";
    console.log(callUrl);
    $.ajax({
        url: callUrl,
        dataType: 'json',
        success: function(response){
            console.log(response);
        },
        statusCode: {
            403: function(response){
                console.log('error');
                console.log(response);
            }
        },
        error: function(response){
            console.log(response);
        }
    });    
}

Note: URL is correct, I can get a 200 statuscode, but I would like to handle the 403 access denied. How do I solve this?


Solution

  • Looks like this call is actually made not using an XHR request but via JSONP. ("callback=?" in your URL) - for JSONP requests, status code information are not available. You will need to make sure that always a valid response is send.

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