无法从jQuery AJAX API调用获取JSON数据 [英] Can't get JSON data from jQuery AJAX API call

查看:199
本文介绍了无法从jQuery AJAX API调用获取JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的API URL返回以下JSON:

My API URL returns the following JSON:

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

这是我的jQuery AJAX调用:

Here is my jQuery AJAX call:

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

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

     }
  });

在chrome中,我可以看到脚本调用以及发送回的数据.但是,当我使用JSON.stringify结果时,我得到的只是:

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"}

为什么不输出我的API数据?

Why is it not outputting my API data?

与我回答中的方括号有关吗?

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

更新:

也许有人可以获得这个jsfiddle来从json响应中输出'name'键? http://jsfiddle.net/T85eB/

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

推荐答案

complete 函数接收XHR对象作为响应.我相信您应该使用.done(function ...)来获取数据:

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

这是从此处获取的: http://api.jquery.com/jquery.ajax/

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

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

     }
  })

;

这篇关于无法从jQuery AJAX API调用获取JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆