Javascript “问题”;XMLHttpRequest无法加载“;在Angularjs和WebApi中
我创建了asp.NETWebAPI并在somee.com上发布。我输入link xxxx.somee.com/api/xxxx就可以了。但我叫安格拉斯不要跑Javascript “问题”;XMLHttpRequest无法加载“;在Angularjs和WebApi中,javascript,angularjs,asp.net-web-api,Javascript,Angularjs,Asp.net Web Api,我创建了asp.NETWebAPI并在somee.com上发布。我输入link xxxx.somee.com/api/xxxx就可以了。但我叫安格拉斯不要跑 $http.get('http://xxxxxx.somee.com/api') .then(function(response) { console.log(response); }); 我收到错误: XMLHttpRequest无法加载xxxx.somee.com/api/xxxx。请求的资源上不存在“Access Contr
$http.get('http://xxxxxx.somee.com/api')
.then(function(response) {
console.log(response);
});
我收到错误:
XMLHttpRequest无法加载xxxx.somee.com/api/xxxx。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“null”
请给出解决方案。非常感谢。如果您的Angular网站和API网站运行在不同的域或端口中,则会发生此问题。 要解决此问题,请将以下代码添加到webapiconfig.cs文件中
var cors = new EnableCorsAttribute(http(s):// xxxx.somee.com/api/xxxx, "*", "*");
config.EnableCors(cors);
请在询问之前尝试搜索该特定错误。在这个网站和整个网络上有成千上万的关于它的问题