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

编程入门 行业动态 更新时间:2024-10-26 18:29:59
本文介绍了无法从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'键? jsfiddle/T85eB/

Perhaps someone can get this jsfiddle to output the 'name' key from the json response? jsfiddle/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:

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

$.ajax({ url: gigniteAPI, dataType: "jsonp") }) .done(function (data) { var ParsedObject = JSON.stringify(data); alert(ParsedObject); } })

;

更多推荐

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

本文发布于:2023-10-29 12:59:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539756.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   AJAX   jQuery   JSON   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!