jQuery ajax 因未知原因失败
我正在调用这样的函数:
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
-
-
在请求选项卡中,我可以看到我的请求没有甚至看起来都不正确(注意缺少授权标头):
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 请求,效果很好)。
I'm calling a function like this:
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));
}
});
In response, the error and complete functions are called, with the resulting output:
[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
When I monitor using Charles, this is what I get:
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
-
-
and in the request tab, I can see that my request doesn't even look right (note the lack of an Authorization 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
What gives? There is no prompt for an unrecognized certificate or anything like that - it just fails. (It works fine if I make a GET request in my browser).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是已知错误
根据记者的说法,解决方法/黑客是要改变jQuery 源代码来自
至
对该错误的评论是这样说的:
<块引用>
感谢您的错误报告,但这是
不是 jQuery 错误。 Windows 7 小工具是
不是受支持的 jQuery 平台。这
新ajax的传输层是
可插拔,所以你应该只包括
忽略正常的自定义传输
跨域支持(或使用
XDomainRequest)。
...和
<块引用>
或者,更简单的是,在脚本中将 jQuery.support.cors 设置为 true,而无需侵入 jQuery ;)
This appears to be a known bug
According to the reporter the workaround/hack is to change the jQuery source from
to
A comment on the bug has this to say:
...and