Hi everyone, I updated ionic to new version and got problem with CORS. when run simulator or upload my app to real device and call any API I got cors error bellow:
[Error] Failed to load resource: Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin. (getOsobniCislaByOrionLogin, line 0)
[Error] XMLHttpRequest cannot load https://xxxxxx.com/getOsobniCislaByOrionLogin?login=bal&outputFormat=JSON. Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin.
[Error] Failed to load resource: Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin. (diet, line 0)
[Error] XMLHttpRequest cannot load http://xxxx.com/diet/. Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin.
so WTF? in simulator and device it should be file:// so why is here now http://localhost:8080? Im getting crazy of it…
Have you got…
<access origin="*" />
In your config.xml?
Also I think you’re using wkwebview running which is the localhost:8080 as it uses a local web server.
Yes <access origin="*" />
is there from app installing. I can see you are right when I confirm old config.xml there is new item
<plugin name="cordova-plugin-ionic-webview" spec="^1.1.14" />
do you know what is this? But Im pretty sure it destroy my app…
OK so the magic is: ionic cordova plugin rm cordova-plugin-ionic-webview
I have no idea why is this plugin in my app now. But I can say is resolved now.
It’s the wkwebview which is the modern safari engine. It’s better and more performant, leave it there.
Ok, but do you know how to make work ajax? Because when I want to call my API nothing is working (just have to say I can not change this API). So is modern but absolutely useless. So pretty shity plugin I can say…
Well I would say your API is “shitty” if this can’t be configured. The plugin is doing its job, making sure the data is allowed to be used on this Origin.
Its not my API so I can not choose. BTW in this APP I use two different API’s and non of them support Access Control Allow Origin so that’s fine this plugin is modern but for most of apps is useless. But anyway this is probably my last app in Ionic and next time try Xamarin. All the time there is lots of bugs in Ionic and is annoying.
Well good luck swapping one set of problems for a new set of problems lol.
If you want to share a repo with us I’ll be happy to take a look, even if you can reproduce the problem in another.
Did you ever figure out the solution?