Angularjs JSONP not working -


i might missing here can't make jsonp request work, here code:

var url =  'http://' + server + '?callback=json_callback'; $http.jsonp(url)     .success(function(data){        console.log('success');     })     .error(function () {       console.log('error')     }); 

the request fires ok , getting response (with header content-type:application/json) in format:

    [{"id": "1", "name": "john doe"},      {"id": "2", "name": "lorem ipsum"},      {"id": "3", "name": "lorem ipsum"}] 

can see wrong? maybe format should return server not right? angular fires error callback without error message besides 1 set ('error').

jsonp requires wrap data javascript function call. technically return javascript file , not json file.

the data returned server should similar this:

// name should match 1 add url json_callback([     {"id": "1", "name": "john doe"},     {"id": "2", "name": "lorem ipsum"},     {"id": "3", "name": "lorem ipsum"} ]); 

edit: if 1 else stumbles across problems angular's jsonp please read this answer question, contains usefull informations how angular handles actual callback function.


Comments

Popular posts from this blog

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -