为了账号安全,请及时绑定邮箱和手机立即绑定

缺少CORS标头“ Access-Control-Allow-Origin”

缺少CORS标头“ Access-Control-Allow-Origin”

UYOU 2019-10-21 10:02:39
我从我的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 回答

  • 3 回答
  • 0 关注
  • 921 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信