我從我的asp.net表單調(diào)用此函數(shù),并在調(diào)用ajax時在Firebug控制臺上收到以下錯誤。跨域請求被阻止:同源策略禁止讀取位于http://anotherdomain/test.json的遠(yuǎn)程資源。(原因:CORS標(biāo)頭“ 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; } });我已經(jīng)做了另一種方法,但仍然找不到解決方案。注意:我沒有更改服務(wù)器端(API / URL)的服務(wù)器權(quán)限。
添加回答
舉報
0/150
提交
取消