Ajax request failing in cordova/phonegap app on real device

五迷三道 提交于 2019-11-30 20:32:40

Well, this is not the kind of answer I was expecting, but this what I did to solve this: create a completely new Cordova 4.0 project and copy there the www folder from the other one. Then build and run in eclipse as usual and everything worked without changing one single line of code anywhere in the project.

I realized the problem wasn't in the code because I noticed that other AJAX calls that I had in the app (and used to work fine) were also failing.

So I don't know if this is some Cordova 4.0 bug or something, but at some point AJAX stopped working. I'm posting this in case someone runs into the same issue.

In my case I was upgrading from cordova 3.7 to cordova 5 Here is what solved it for me: add the plugin cordova-plugin-whitelist

Because of New Content Security Policy for android Ajax Requests are blocked.

try following and see if that works.

Open your config.xml

Replace

<access origin="*" />

With

<access origin="http://*" />
<access origin="https://*" />

prepare the phonegap project and build it again and check on real device.

Regards, Jagat

Turns out I was just missing the following plugin:

cordova-plugin-whitelist

After I installed it, remove the android platform, re-added the android platform, build and run, it worked!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!