Reputation: 37
Here is my web service that works perfectly fine in Fiddler and in my browser: http://localhost:11458/PlayerSvc.svc/GetPLayers
I then tried to call this via Jquery in phonegap and it failed: here is my jquery in phonegap using Eclipse:
<script type="text/javascript">
$.ajax({
url: 'http://localhost:11458/PlayerSvc.svc/GetPlayers',
dataType: 'json',
// timeout: 55000,
// beforeSend: function(xhr) {
//Possible to set any required headers here
//xhr.setRequestHeader('Authorization', 'username password');
// },
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('failed');
},
success: function(data) {
alert('success');
}
});
</script>
To make sure there was nothing wrong with my jquery I tested another webservice with this code and it was successful. I am not sure how to gather more information on how to debug this. I tried wrapping my javascript with console.log(javascript above) and I could not get that to work. As you can see above I just used the alert function to output the failed error message. Any ideas? I think i may try using a try catch and then seeing if I can output the exception...
Upvotes: 1
Views: 2099
Reputation: 1250
Are you running the PhoneGap application in the Android emulator? If yes, I think the localhost (127.0.0.1) in the emulator refers to the emulator itself and not the host machine. Perhaps you need to try another IP address (possibly 10.0.2.2 works).
Here's a question/answer that addresses this issue:
test the localhost in android emulator
Upvotes: 3
Reputation: 53
You need to allow whitelist urls and add your host address to external hosts in your phonegap.plist file.
http://geekaboo.wordpress.com/2011/11/20/ios5-whitelist-url-unauthorized-using-phonegap/
Upvotes: 0