否'访问控制允许来源'标头存在于请求的资源上.起源'http://localhost:8100&

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access

本文关键字:资源 起源 请求 8100 http localhost 于请求 访问控制 存在      更新时间:2024-04-15

大家好,我正在为magento开发一款ionic应用程序,我是ionic的初学者,我也在使用谷歌chrome浏览器,但当我在浏览器中使用ionic serve命令应用程序正在运行,但它是空的,我在控制台中收到此错误

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

我搜索了很多,找到了使用此扩展的解决方案允许控制允许来源:*

当我使用此扩展时,错误已修复,但应用程序仍然为空,浏览器中不会显示数据,但当我在PhoneGap或设备中运行此应用程序时,它工作正常,并从magento获取所有数据。我没有服务器访问安装这个magento网站的地方。。

如果您正在使用Google chrome,则可以添加一个插件:https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

它为我解决了这个问题。

不幸的是,您需要在磁电机服务器上设置/无法设置CORS。您可以尝试为离子服务设置代理-请查看此处:http://blog.ionic.io/handling-cors-issues-in-ionic/

在你的.项目文件中:

{
  "name": "proxy-example",
  "app_id": "",
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "http://mad.xs4arabia.com"
    }
  ]
}

所以在您的服务/控制器中:

$http.get('/api/myendpoint') 

这将决定:

http://mad.xs4arabia.com/myendpoint