javascript - Angularjs $http cant get data but can get from $jquery.ajax -
i tired data off api using jquery.ajax() , works fine
here code that:
$.ajax({ url: "http://api.somesite.com/api?format=json", type: "get", //it works post datatype: 'jsonp', }) .done(function( data ) { if ( console && console.log ) { console.log( "sample of data:", data ); } }); now wanted same angularjs did following
first did this:
var req = { method: 'get', url: "http://api.somesite.com/api?format=json", headers: { 'content-type': "application/json", }, } $http(req).then(function(response){ console.log(response.data); }); i in console:
xmlhttprequest cannot load http://api.somesite.com/api?format=json. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8100' therefore not allowed access. then tried this:
$http.jsonp('http://api.somesite.com/api?format=json', { headers: { "content-type":"application/json", "accept" : "application/json" }}).success(function(data, status) { console.log(status); console.log(data); }). error(function(data, status) { console.log(status); console.log(data); }); i error code 404 , data undefined
kindly tell how accomplish. not have access serve or api cannot modify api in way.
Comments
Post a Comment