Reputation: 2384
I am working on phonegap and trying to get list of user using ajax call but my function is returning nothing on mobile its working fine in browser
here is the function and url data is in xml format
$(document).ready(function(){
$.ajax({
type: "POST",
url: "http://my_server_url/user/selectuser",
dataType: 'jsonp',
crossDomain: true,
processData: true,
cache: false,
success: function(data)
{
alert("Success:"+data.detail[0].Username);
},
error: function(data){
alert("Error:"+data);
},
statusCode: {
404: function() {
alert( "page not found" );
}
}
});
});
Thanks
Upvotes: 2
Views: 110
Reputation: 327
With Phonegap version "Cli-5.2.0", whitelist plugin need to be use to successfully make ajax call on Android. Add below mentioned line in config.xml to use whitelist plugin with Phonegap cloud build.
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
Check https://github.com/apache/cordova-plugin-whitelist for whitelist plugin description
Upvotes: 0
Reputation: 14526
The general steps I go through for checking problems like this on mobile are:
GET
request, but it may at least help you figure out if your phone can reach your server.GET
request (like you are here), you can try running your own AJAX request directly in the debugger console. If you duplicate the request exactly, it shouldn't give you any more information than watching the regular request in the network tab, but it does allow you to modify the request multiple times without recompiling your app. It can be a huge time-saver.If your phone can't reach the resource at all (#1) then maybe you have a specialized local environment that your phone doesn't share. For example, you might be calling localhost
or 127.0.0.1
, which your phone will never reach (because these IP addresses have a special meaning on most networks and basically means 'me' or 'this computer'). Or maybe you're calling out to something like 192.168.xxx.xxx
or 10.xxx.xxx.xxx
, which your phone can't reach because it isn't on that private network (e.g if you are not on the same wifi). In this case, you have two options:
Upvotes: 1