简体   繁体   English

无法从jQuery AJAX API调用获取JSON数据

[英]Can't get JSON data from jQuery AJAX API call

My API URL returns the following JSON: 我的API URL返回以下JSON:

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

Here is my jQuery AJAX call: 这是我的jQuery AJAX调用:

$.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. 在chrome中,我可以看到脚本调用以及发送回的数据。 However when I JSON.stringify the result all I get is: 但是,当我JSON.stringify结果时,我得到的是:

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

Why is it not outputting my API data? 为什么不输出我的API数据?

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? 也许有人可以让这个jsfiddle从json响应中输出'name'键? http://jsfiddle.net/T85eB/ http://jsfiddle.net/T85eB/

The complete function receives the XHR object as a response. complete函数接收XHR对象作为响应。 I believe you should be using .done(function...) to get the data: 我相信你应该使用.done(function ...)来获取数据:

This is taken from here: http://api.jquery.com/jquery.ajax/ 这是从这里获取的: http : //api.jquery.com/jquery.ajax/

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

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

     }
  })

; ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM