javascript - Can a webservice not support JSONP? -


i trying data using worldbank api. webservice call making this. code doesnt work.

$.ajax({   type: 'get',   url: 'http://api.worldbank.org/countries/indicators/3.1_low.sec.new.teachers?per_page=50&date=1960:2013&format=json',   jsonpcallback: 'jsoncallback',   contenttype: "application/json",   datatype: 'jsonp',   success: function(data) {      console.log(data);   },   error: function(e) {      console.log(e.message);   } }); 

any appreciated!

json , jsonp entirely different things. you're asking json, telling jquery you're asking jsonp. that's not going work.

it support jsonp if tell to. should use format=jsonp , prefix=the_name_of_your_callback. since want jquery control callback name, want jsonp argument tell api uses non-standard prefix argument (rather callback, standard one).

$.ajax({   url: 'http://api.worldbank.org/countries/indicators/3.1_low.sec.new.teachers?per_page=50&date=1960:2013&format=jsonp',   jsonp: 'prefix',   datatype: 'jsonp',   success: function(data) {      console.log(data);   },   error: function(e) {      console.log(e.message);   } }); 

working example | source

notes on above:

  • removed type: "get". jsonp always get.
  • changed format=json format=jsonp in url.
  • removed jsonpcallback: 'jsonpcallback'. argument tells jquery use specific name callback function, don't want.
  • added jsonp: 'prefix', tells jquery argument use in query string name of callback function. api documents uses prefix instead of more standard callback.
  • removed contenttype: "application/json". you're not sending json, you're expecting receive json.

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -