0
我有一个Django服务器amd我想用AngularJS发送一个请求给它。AngularJS发送请求x-www-form-urlencoded
这是我的代码:
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这个要求吗?