I'm new to JQuery and maybe this is a n00b question. And also my English is not the best.
I wrote a service in my Google App Engine application who delivers data in JSON format, which works OK, but I wasn't able to parse that JSON data using JQuery:
var url= 'myapp.appspot.com/myservice.json?someparams';
$.getJSON(url, function(json){
alert("Success parsing JSON"); // I never reached this code
....
});
After a few days of reading posts and tutorials I felt into this SlideShare: http://www.slideshare.net/andymckay/cross-domain-webmashups-with-jquery-and-google-app-engine
While reading slide 23 I noticed about the "callback=?" parameter and I tried the code in slide 42:
class MyJSONHandler(webapp.RequestHandler):
def get(self):
## Retrieve some data from DB or MemCached
jsonData = json.dumps(data)
if self.request.get('callback'):
self.response.out.write('%s(%s)' % (self.request.get('callback'), jsonData))
else:
self.response.out.write(jsonData)
And in the JQuery function:
$.getJSON(url+'&callback=?', function(json){
alert("Success parsing JSON"); // Now i'm here !!
....
});
My question is:
Why is the "callback" parameter necessary to make this work? What difference does the '?("MyJSON": [{"a-lot" : "of-data"}])' makes??
Thanks you all.