jquery - jsonp failing gives 404 -


to understanding, happens:

  1. jsonp wraps json in function.
  2. when using jsonp, have specify name of function used in (1)
  3. 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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -