所有, 我有一個在IE(我知道對不對?),但工作正常下AJAX請求時,我嘗試使用Chrome瀏覽器相同的代碼,我得到了以下錯誤:鉻阻擋Ajax請求
XMLHttpRequest cannot load http://ahmwpsds01:1234/NASAService/GetNASAUser.asmx/GetUserByName . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://ahmwpsds01 ' is therefore not allowed access. The response had HTTP status code 500.
Ajax請求
function getNASAProfile(user) {
var dfd = new $.Deferred(function() {
$.support.cors = true;
$.ajax({
type: "POST",
url: "http://ahmwpsds01:1234/NASAService/GetNASAUser.asmx/GetUserByName",
data: "{userName: '" + UserProfile.Name + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
})
.done(function (data) {
//alert('Call Succeeded');
dfd.resolve(data.d);
})
.fail(function (jqXHR, textStatus, errorThrown) {
alert('Call Failed\n\n' + jqXHR.statusText + "\n\n" + errorThrown + "\n\n" + textStatus);
});
});
return dfd.promise();
}
有什麼想法?
是啊,典型的CORS錯誤。 IE不正確地允許它,或者不發送給定請求應該要求的OPTIONS預檢請求。 –
這就是它說的。您正在請求的網址需要一個Access-Control-Allow-Origin標題。 https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Origin – danielrsmith
不,我不這麼認爲,因爲我發送$ .support.cors,它的工作原理IE瀏覽器。 –