Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phonegap 5.2 ajax calls throwing 404 recently [duplicate]

I had a code that was working fine in my local and phonegap build untill a week back. Now All my internet calls have started to fail. ajax to start with. I am getting a response of 404.

I have seen below links and lot more that are similar to them. Just adding of plugin and access-origin = "*" seem to be solving their problem. I had the plugin earlier as well and now I added source and version additionally to the plugin to try.

My guess is I am missing something minor or basic here my code. Phonegap build I am using is 5.2

URLs for reference : Cordova / Phonegap All External Ajax Requests Returns 404 Phonegap Build .ajax request returning 404

manifest has below lines :

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

config.xml

<access origin="*" />
<plugin name="cordova-plugin-whitelist"  source="npm" version="1.1.0" />
<allow-intent href="*" />
<allow-navigation href="*" />

ajax call code :

var url_built_for_ip = "http://abc.xyz.com/whatsMyName/abc";

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
{
alert("state changed "+xmlhttp.status)
}
xmlhttp.open("GET",url_built_for_ip,true);
xmlhttp.send();

NOTE : When I run the same code from my phonegap app, it runs fine (ajax calls work fine.) This might look like a duplicate question but it is not, as I have refered the other questions that are providing a solution to similar pronblem, it's just that those solutions are not working for me.

Thank you for your support !!!

like image 648
algae514 Avatar asked Sep 28 '15 10:09

algae514


1 Answers

I just had this issue and i did a few things to fix it, not sure which fixed it.

  • ran cordova plugin remove cordova-plugin-whitelist
  • ran cordova plugin add cordova-plugin-whitelist@latest
  • ran cordova prepare android
  • deleted the app from the android phone
  • ran cordova run android --device

and now it works.

like image 53
Post Impatica Avatar answered Dec 20 '22 03:12

Post Impatica