Phonegap Android getJSON

I am taking the first steps in PhoneGap with Android (why do you need to choose a platform, anyway? This should be cross-platform!). I am trying to call a RESTful service, get JSON in return and put it on the screen. The tutorials for this are incredibly hard to find. I am using the following code:

<!DOCTYPE HTML> <html> <head> <title>JSON Demo</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $.getJSON('http://MyServerIP/json/GetJobDetails/717/MyKey?callback=?', { success:function(data) { data = evalJSON(data); $('body').append('<strong>X </strong>'); }, error: function() { $('body').append('<strong>Error </strong>'); } }); </script> </head> <body> test 10 </body> </html> 

... But I get no answer, no success, no mistake. The server reports that it was hit, and returned the data. Viewing a single URL also returns data. Why doesn’t anything appear in the emulator?

0
json android cordova
source share
2 answers

For some reason, success: and error: they killed him, i.e. it works:

  <script type="text/javascript"> $.getJSON('http://MyServerIP/json/GetJobDetails/717/MyKey?callback=?', function(data) { data = evalJSON(data); $('body').append('<strong>X </strong>'); }); </script> 
+2
source share

You can find a good tutorial about Android + jquery mobile here on the official PhoneGAP wiki here: http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile

For your problem, make sure this line is in the phonegap application manifest file: <use-permission android: name = "android.permission.INTERNET"> </ uses-permission>

In addition, you can configure server headers like this: 'Access-Control-Allow-Origin: *'

Good luck

+2
source share

All Articles