Reputation: 6729
I'm taking my first steps in PhoneGap with Android (How come you have to pick a platform, anyway? It's supposed to be cross-platform!). I'm trying to call a RESTful service, get some JSON in return and put it on the screen. Tutorials for this are incredibly hard to find. I'm 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 response, neither success nor error. The server reports that it has been hit though, and returned the data. Browsing to the same URL also returns data. How come nothing appears in the emulator?
Upvotes: 0
Views: 4835
Reputation: 6729
For some reason the success: and error: were killing it, ie this works:
<script type="text/javascript">
$.getJSON('http://MyServerIP/json/GetJobDetails/717/MyKey?callback=?', function(data)
{
data = evalJSON(data);
$('body').append('<strong>X </strong>');
});
</script>
Upvotes: 2
Reputation: 1156
You can find a good tutorial about Android + jquery mobile here in the official wiki of PhoneGAP here: http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile
For your problem Make sure this line is in phonegap app manifest file: < uses-permission android:name="android.permission.INTERNET" >< /uses-permission >
Plus, you can set the server headers to: 'Access-Control-Allow-Origin: *'
Good Luck!
Upvotes: 2