Phonegap Cordova Ajax requests 404 (Not Found) Err

2019-01-13 05:30发布

My cordova version is 5.0.0

I am getting a 404 error for the all ajax request made when the app is deployed on the device. On the web browser, it works fine but same app when deployed on a device does not work.

I tried adding following to solve the issue but it hasn't helped.

Config.xml

<access origin="*" />

AndriodManiest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

I also added following in my index.html file but it didn't make any difference either.

<script>
    $.support.cors=true;
</script>

Anyone here has another trick to solve this issue?, Seems to be a quite common issue with phonegap but the fixes above worked in older vesion of the phonegap/cordova but non of them has worked in my case.

Any help would be great.

4条回答
We Are One
2楼-- · 2019-01-13 05:44

This worked for me. The only difference is in my config.xml I had to put it in an node for it to take effect.

My example below:

<platform name="android">
    <allow-intent href="market:*" />
    <access origin="*" />
    <allow-intent href="*" />
    <allow-navigation href="*" />
</platform>
查看更多
【Aperson】
3楼-- · 2019-01-13 05:55

I had the same issue and had to install the cordova-plugin-whitelist

cordova plugin add cordova-plugin-whitelist

Credit goes to this stackoverflow article - Ajax Command to request URL no longer working

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-13 05:55

Phonegap User. Adding this line into the config.xml is the solution for me:

<gap:plugin name="cordova-plugin-whitelist" source="npm" />
查看更多
Ridiculous、
5楼-- · 2019-01-13 06:06

It should actually add the cordova whitelist plugin :

cordova plugin add cordova-plugin-whitelist

or in your config.xml file :

<plugin name="cordova-plugin-whitelist" spec="1" />

but if you are using the online phonegap build service the syntax is different. You have to add the following line in your config.xml file :

<gap:plugin name="cordova-plugin-whitelist" source="npm" />

and authorize cross domain requests :

<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />

This is not recommended because a wildcard is used everywhere and everything is permitted. But it is perfect for your tests.

查看更多
登录 后发表回答