jquery - jsonp failing gives 404 -
to understanding, happens:
- jsonp wraps json in function.
- when using jsonp, have specify name of function used in (1)
- receive data normal josn
is understanding right ? please correct me if im wrong
if im correct, why doesnt code work? im trying access small local jsonp file givs me 404
(function ($) { var url = 'dummy.jsonp?callback=?'; $.ajax({ type: 'get', url: url, async: false, jsonpcallback: 'wrapper', contenttype: "application/json", datatype: 'jsonp', success: function (json) { alert(json); }, error: function (e) { console.log(e.message); } }); })(jquery);
dummy.jsonp:
wrapper([ { "id":1, "name":"clark" }, { "id":2, "description":"kent" } ])
edit: turns out @xdazz right, when uploaded file on public server accessed how fix work relative paths? both page , dummy.jsonp in same folder
what doing wrong ?
as server response looks that. should have wrapper()
method in client side.
add such function in client side code,
function wrapper(data) { alert(data[0].id); } (function ($) { var url = 'dummy.jsonp?callback=?'; $.ajax({ type: 'get', url: url, datatype: 'jsonp', success: function (json) { alert(json); }, error: function (e) { console.log(e.message); } }); })(jquery);
Comments
Post a Comment