我從我的asp.net表單調用此函數,并在調用ajax時在Firebug控制臺上收到以下錯誤。跨域請求被阻止:同源策略禁止讀取位于http://anotherdomain/test.json的遠程資源。(原因:CORS標頭“ Access-Control-Allow-Origin”缺失)。var url= 'http://anotherdomain/test.json'; $.ajax({ url: url, crossOrigin: true, type: 'GET', xhrFields: { withCredentials: true }, accept: 'application/json' }).done(function (data) { alert(data); }).fail(function (xhr, textStatus, error) { var title, message; switch (xhr.status) { case 403: title = xhr.responseJSON.errorSummary; message = 'Please login to your server before running the test.'; break; default: title = 'Invalid URL or Cross-Origin Request Blocked'; message = 'You must explictly add this site (' + window.location.origin + ') to the list of allowed websites in your server.'; break; } });我已經做了另一種方法,但仍然找不到解決方案。注意:我沒有更改服務器端(API / URL)的服務器權限。
- 3 回答
- 0 關注
- 1132 瀏覽
相關問題推薦
添加回答
舉報
0/150
提交
取消