简体   繁体   English

jQuery似乎无法通过Ajax调用状态码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. 我遇到了一个有趣的情况,我不确定这是我的错还是jQuery的错,因此我想向大家咨询。

Currently I am doing an Ajax call, which returns a 403 status code. 当前,我正在执行Ajax调用,该调用返回403状态代码。 But the string accompanying that 403 is different from the standard. 但是403附带的字符串与标准不同。

It returns 403 access denied but according to specification it should be 403 Forbidden . 它返回403 access denied但是根据规范它应该是403 Forbidden

I know how to get a 200 statuscode from the server, the question is more in how to handle this situation. 我知道如何从服务器获取200状态代码,问题更多在如何处理这种情况。

This is my Ajax jQuery code, and it does not get in any of the console.log() situations. 这是我的Ajax jQuery代码,在任何console.log()情况下都不会得到。

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 . 注意:URL是正确的,我可以获得200状态代码,但是我想处理403 access denied How do I solve this? 我该如何解决?

Looks like this call is actually made not using an XHR request but via JSONP. 看起来此调用实际上不是使用XHR请求而是通过JSONP进行的。 ("callback=?" in your URL) - for JSONP requests, status code information are not available. (您的网址中的“ callback =?”)-对于JSONP请求,状态代码信息不可用。 You will need to make sure that always a valid response is send. 您将需要确保始终发送有效的响应。

See http://api.jquery.com/jQuery.ajax/ 参见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. http://en.wikipedia.org/wiki/HTTP_403检查引发错误的目录的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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