gpt4 book ai didi

javascript - jQuery ajax 因未知原因失败

转载 作者:行者123 更新时间:2023-11-30 18:45:54 26 4
gpt4 key购买 nike

我正在调用这样的函数:

function(activeOnly, callback) {
debug("$.support.cors: {0}".format($.support.cors));
debug("getting data({0})".format(activeOnly));
debug("{0}/data/".format(this._api_root));
$.ajax({
url: "{0}/data/".format(this._api_root),
data: {
generaldata: !activeOnly
},
dataType: "json",
headers: {
authorization: this._auth_header
},
success: function (data, code, jqx) {
debug("data request succeeded with {0}".format(data));
result = data;
},
error: function(jqx, err, ex) {
debug("data request failed with {0}: {1}".format(err, ex));
},
complete: function(jqx, status) {
debug("data request completed: {0}".format(status));
}
});

作为响应,错误和完整函数被调用,结果输出:

[6192] MyData: $.support.cors: true
[6192] MyData: getting data({0})
[6192] MyData: https://_some_root_/data/
[6192] MyData: data request failed with Unknown: Unknown
[6192] MyData: data request completed: Unknown

当我使用 Charles 进行监控时,这是我得到的:

https://_some_root_/
Failed
No request was made. Possibly the certificate was rejected.
-
HTTP/1.0
CONNECT
-
/127.0.0.1
_some_root_/_some_ip_address_

3/31/11 3:15:28 PM
-
-
-
-
-
-
-
0.02 KB/s
-

366 bytes
-
-
-
366 bytes
-
-

在请求选项卡中,我可以看到我的请求甚至看起来都不正确(注意缺少授权 header ):

CONNECT _some_root_:443 HTTP/1.0
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; Tablet PC 2.0)
Host: _some_root_:443
Content-Length: 0
Proxy-Connection: Keep-Alive
Pragma: no-cache

什么给了?没有提示无法识别的证书或类似的东西 - 它只是失败了。 (如果我在浏览器中发出 GET 请求,它工作正常)。

最佳答案

这似乎是 a known bug

  1. 根据记者的说法,解决方法/hack 是将 jQuery 源更改为

    jQuery.support.cors = testXHR && ( "withCredentials" in testXHR );

    jQuery.support.cors = true; 
  2. 对该错误的评论是这样说的:

    Thanks for the bug report, but this is not a jQuery bug. Windows 7 Gadgets is not a supported jQuery platform. The transports layer of new ajax is pluggable, so you should just include a custom transport that ignores normal cross-domain support (or uses XDomainRequest).

  3. ...和

    Or, more simply, set jQuery.support.cors to true in your script without hacking into jQuery ;)

关于javascript - jQuery ajax 因未知原因失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5505802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com