我打電話這樣的功能: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
當我使用查爾斯的監視器,這是我得到:
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請求,它工作正常)。
可以嘗試在您的AJAX請求中添加'cache:false'? – 2011-03-31 22:44:33
@LekisS:我試過了,它不起作用。沒有意外的是:對於'dataType:「json」','cache'默認設置爲false。 – 2011-03-31 22:54:33
@ben是這個跨域ajax? – kjy112 2011-03-31 23:20:47