callback function parsing JSON in JQuery -


i'm new jquery , maybe n00b question. , english not best.

i wrote service in google app engine application delivers data in json format, works ok, wasn't able parse json data using jquery:

 var url= 'myapp.appspot.com/myservice.json?someparams'; $.getjson(url, function(json){     alert("success parsing json");  // never reached code      .... }); 

after few days of reading posts , tutorials felt slideshare: http://www.slideshare.net/andymckay/cross-domain-webmashups-with-jquery-and-google-app-engine

while reading slide 23 noticed "callback=?" parameter , tried code in slide 42:

 class myjsonhandler(webapp.requesthandler):     def get(self):         ## retrieve data 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 jquery function:

 $.getjson(url+'&callback=?', function(json){     alert("success parsing json");  // i'm here !!     .... }); 

my question is:

why "callback" parameter necessary make work? difference '?("myjson": [{"a-lot" : "of-data"}])' makes??

thanks all.

the callback parameter used implement jsonp.

jquery's getjson method creates <script> tag point url give it.
url expected return call function specified in callback parameter, passing data parameter.

unlike normal ajax requests, jsonp requests can made across domains.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -