Software Archive
Read-only legacy content
17061 Discussions

Unable to get ajax calls to work on real Android device

David_K_6
Beginner
1,126 Views

I have an app that makes Ajax calls from jQuery. It works fine in simulation from XDK. When built using PhoneGap Build, it works fine on an iPhone, and on an Android device using the PhoneGap app, but not on the Android device when loaded from a .apk file - the ajax call just calls the error callback with status 0.

Here is some trivial code just to test this ability:

$.ajax({
  dataType:'json',
  url: 'https://api.github.com/users/mralexgray/repos',
  type: 'GET',
  success:function(data){
    console.log("Got some json from github");
  },
  error: function(jqXHR) {
    console.log("Failed to get github: " +jqXHR.status);
  }
});

I have included the Cordova Whitelist plugin in config.xml. I have tried both leaving access at "*" and explicitly including "https://api.github.com", either in the plugin with an <access> keyword in config.xml, or as a <meta> tag in index.html. Nothing has worked, so far.

I badly need some help here! I'm guessing that this is a browser security issue or a version issue of some sort, but I can't figure it out.

0 Kudos
3 Replies
PaulF_IntelCorp
Employee
1,126 Views

David K. wrote:

When built using PhoneGap Build, it works fine [...] on an Android device using the PhoneGap app, but not on the Android device when loaded from a .apk file

I don't understand what you mean by "on an Android device using the PhoneGap app" in your statement above. Can you clarify? It sounds like you are running your app on an Android device under two different conditions. What do you mean by "the PhoneGap app"? It will help to understand what the differences are between your run conditions.

0 Kudos
David_K_6
Beginner
1,126 Views

In the mean time, after many hours of work, I think I've found the problem: Ajax calls started working again when I added a key to my Android build in the PhoneGap Build screen.

See https://phonegap.com/products/#mobile-app-section and https://phonegap.com/products/#desktop-app-section for Adobe's documentation of the app combination that I am calling "the PhoneGap app".

0 Kudos
PaulF_IntelCorp
Employee
1,126 Views

Thanks for the update, David. Glad you figured out what was not working.

0 Kudos
Reply