var url= 'http://sample.net:8051/admin/singleprofile';
$.ajax({
url: url,
crossOrigin: true,
type: 'GET',
xhrFields: { withCredentials: true },
accept: 'application/json'
}).done(function (data) {
console.log(data);
}).fail(function (xhr, textStatus, error) {
var title, message;
switch (xhr.status) {
case 403:
title = xhr.responseJSON.errorSummary;
console.log('Please login to your server before running the test.');
break;
default:
title = 'Invalid URL or Cross-Origin Request Blocked';
console.log('You must explicitly add this site (' + window.location.origin + ') to the list of allowed websites in your server.');
break;
}
});
从上面的代码中我得到以下问题: 必须明确这个网站(' + window.location.origin + ')
添加到列表允许您的服务器上的网站。跨来源请求阻止:同源策略不允许读取远程资源访问http://sample.ent
您需要完全按照错误说明的内容进行操作:将您的起源添加到允许的CORS列表中,以便从服务器发送标头'Access-Control-Allow-Origin:http:// sample.net'。 –