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); } });
notes on above:
- removed
type: "get"
. jsonp alwaysget
. - 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 usesprefix
instead of more standardcallback
. - removed
contenttype: "application/json"
. you're not sending json, you're expecting receive json.
Comments
Post a Comment