【发布时间】:2014-08-06 06:49:02
【问题描述】:
我启动了一个显示来自 http 服务器的数据的 Web 应用程序项目。如果我运行 webServer.js(通过安装的 node/express 实现),则 index.html 将被执行。因为服务器(数据来自哪里)有另一个域,所以我收到以下错误:
XMLHttpRequest cannot load *"http-link to Server"*. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
据我了解,只有两种解决方案:
- 将 Web 应用程序项目文件加载到服务器:同域, 同出处。
- 使用 CORS(跨源资源)解决问题 分享)方法。
我无法继续解决方案 1。因此,我必须使用 CORS 实施第二个解决方案。谁能解释我必须实现什么、如何以及在哪里(webServer.js 或 index.html)?我确实上网查了,但我不明白。我应该使用哪些额外的库?关键字是 angular.js 或 jsonp...
感谢您的帮助!干杯。
【问题讨论】:
标签: javascript angularjs xmlhttprequest jsonp cors