Robjocky
Robjocky

Reputation: 47

Can't get JSON data from jQuery AJAX API call

My API URL returns the following JSON:

[{"_id":{"$id":"529c759d361ae724088b4568"},"name":"1877","soundcloud_url":"","genres":["rock","electro"]}]

Here is my jQuery AJAX call:

$.ajax({
 url: gigniteAPI,
 dataType: "jsonp",
 complete: function (data) {

     var ParsedObject = JSON.stringify(data);
     alert(ParsedObject);

     }
  });

In chrome I can see the script call and that the data that is sent back. However when I JSON.stringify the result all I get is:

{"readyState":4,"status":200,"statusText":"success"}

Why is it not outputting my API data?

Is it to do with the square brackets in my response?

UPDATE:

Perhaps someone can get this jsfiddle to output the 'name' key from the json response? http://jsfiddle.net/T85eB/

Upvotes: 0

Views: 2081

Answers (1)

Hayes
Hayes

Reputation: 858

The complete function receives the XHR object as a response. I believe you should be using .done(function...) to get the data:

This is taken from here: http://api.jquery.com/jquery.ajax/

$.ajax({
    url: gigniteAPI,
    dataType: "jsonp")
})
.done(function (data) {

     var ParsedObject = JSON.stringify(data);
     alert(ParsedObject);

     }
  })

;

Upvotes: 3

Related Questions