Angular JS请求远程Sails服务器

时间:2015-08-18 21:00:14

标签: angularjs node.js http sails.js same-origin-policy

我正在尝试使用前端的AngularJS向使用Sails JS(NodeJS)运行的远程服务器发出请求,并且我收到此来源'null'错误:

XMLHttpRequest cannot load http://remoteserver:1337/login/. The 'Access-Control-Allow-Origin' header contains the invalid value ''. Origin 'null' is therefore not allowed access.

我的请求看起来像是:

$http.post('http://remoteserver:1337/login/', { email: userData.email, password: userData.password}); 

有什么想法吗?

1 个答案:

答案 0 :(得分:6)

您需要服务器启用CORS(跨源资源共享),

来自Sails.js cors文档(http://sailsjs.org/documentation/concepts/security/cors

  

要允许来自任何域的跨源请求到您应用中的任何路由,只需在config / cors.js中启用allRoutes:   allRoutes: true

以下是关于CORS是什么以及为什么需要它的简要说明:

http://enable-cors.org/index.html

相关问题