简体   繁体   中英

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?

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/

Reference this to see if you can determine the specific denial. http://en.wikipedia.org/wiki/HTTP_403 Check the settings of the directory that's throwing the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM