首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS发送请求x-www-form-urlencoded

AngularJS发送请求x-www-form-urlencoded
EN

Stack Overflow用户
提问于 2016-05-14 00:16:00
回答 1查看 70关注 0票数 0

我有一个Django服务器,我试图使用AngularJS向它发送一个请求。

这是我的密码:

代码语言:javascript
复制
           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);
            });

我得到了以下错误:

代码语言:javascript
复制
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中建议这个请求有什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-14 00:43:23

代码似乎不需要这个部分:

'Access-Control-Allow-Origin': '*',

真正的问题在于服务器不允许本地urls。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37221090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档