1

I am trying to get some json data from an api it works with jquery but doesn't work with angularjs?

I am using Ionic to code the app.

I don't think it is a CORS issue, if it were the jQuery code wouldn't work.

in jQuery i do the following: (Working)

$.ajax({
 url: "http://api.somesite.com/api?format=json",
  type: "GET", //it works with POST as well
  dataType: 'jsonp',
 })
  .done(function( data ) {
    if ( console && console.log ) {
      console.log( "Sample of data:", data );
    }
  });

console result: http://imgmonkey.com/hfrk2cbfz1gi/firstSuccess.png.html

This is the Angularjs Code: (Not Working)

 url="http://api.somesite.com/api?format=json";

 $http.jsonp(url)
 .success(function(data, status, headers, config) {
   console.log(data);
    console.log(status);
     console.log(headers);
    console.log(config);
})
.error(function(data, status, headers, config) {
    console.log(data);
    console.log(status);
     console.log(headers);
    console.log(config);
});

console result: http://imgmonkey.com/v16ug212dm0d/second_fail.png.html

1 Answer 1

1

if you want to use jsonp with angular you need a query string of "callback=JSON_CALLBACK"

url="http://api.somesite.com/api?format=json&callback=JSON_CALLBACK";

Sign up to request clarification or add additional context in comments.

1 Comment

the api has wm=nX2X3 at the end like so url="api.somesite.com/api?format=json&cwm=nX2X3";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.