我有一个Django服务器,我试图使用AngularJS向它发送一个请求。
这是我的密码:
var req = {
method: 'POST',
url: 'http://127.0.0.1:8000/api/user/register/',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/x-www-form-urlencoded'
},
data: $.param({ phone_number: phonenumber, password: phonenumber, country: 1 })
}
$http(req).then(function(response){
callback(response);
}, function(response){
console.log(response);
});我得到了以下错误:
XMLHttpRequest cannot load http://127.0.0.1:8000/api/user/register/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1' is therefore not allowed access.我不知道这里有什么问题。我已经为iOS和Android创建了一个应用程序,它们都可以与同一台服务器通信,而且我没有任何问题。
我使用的是AngularJS 1.5.5 https://code.angularjs.org/1.5.5/
有人能在AngularJS中建议这个请求有什么问题吗?
发布于 2016-05-14 00:43:23
代码似乎不需要这个部分:
'Access-Control-Allow-Origin': '*',
真正的问题在于服务器不允许本地urls。
https://stackoverflow.com/questions/37221090
复制相似问题