ionic problem No 'Access-Control-Allow-Origin'

后端 未结 4 803
独厮守ぢ
独厮守ぢ 2020-12-19 00:10

I\'m working on an ionic apps. My problem is: when I try to get data from server I got this:

XMLHttpRequest cannot load https://mywebsite.com/api. No

4条回答
  •  别那么骄傲
    2020-12-19 00:42

    This cors problem has a simple work around in ionic.

    Go to your ionic.config.json (previously ionic.project) and add a proxy for example:

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

    After that use "/api/" instead of "https://mywebsite.com/api" when you call your api.

    For more info:

    http://blog.ionic.io/handling-cors-issues-in-ionic/

提交回复
热议问题