【发布时间】:2015-04-06 18:16:33
【问题描述】:
在我的应用程序中,我将 angularjs 和 cordova 用于前端,将 express 和 node js 用于充当服务器的后端。我的客户端在 http://localhost:9000 上运行,但是我的 express js 在 http://localhost:3000 上运行。我需要从 express API 获取数据。访问时,它说'
XMLHttpRequest cannot load http://localhost:3000/data. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
为此,我需要添加res.addHeader("Access-Control-Allow-Origin", "*")。它是从另一个域访问一个域。如何在 express js 中添加此标头?请帮帮我..
【问题讨论】:
标签: angularjs node.js express httprequest access-control