[英]Giphy API - can't figure out how to call the data once I've made the AJAX call
我目前在一个简单的网站上工作,该网站使用Giphy API( https://github.com/Giphy/GiphyAPI )捕获随机gif。 现在我只是在练习,所以我正在尝试制作一个非常裸露的网站。 我的问题是我无法弄清楚如何使用jQuery正确获取数据。 当我将其登录到控制台时,这是来自API的数据当前的外观。 我似乎一点也抓不到。 我将如何获取这些数据? 例如,如果我想要第一个结果的bitly_url,我的第一个直觉将是data [0] .bitly_url,但这是行不通的。 请帮忙!
这是我的HTML:
<body>
<h1 class="animated infinte bounce"> GIFs-A-Go-Go </h1>
<div class="info">
<p> Is it GIF with a hard G? Or GIF with a soft G (Jif)? Whatever! Let's get some! </p>
<form class="zipform">
<input type="text" class="pure-input-rounded">
<button type="submit" class="pure_button"> Search for GIFs </button>
<input type="reset" value="Reset">
</form>
<div class="rando_facts animated bounceIn">
<p id="here_is_gif"> </p>
</div>
</div>
还有我的jQuery / JS文件:
$('.pure_button').click(function(e) {
e.preventDefault()
console.log("click noticed")
$.ajax({
url: "http://api.giphy.com/v1/gifs/search?q=" + $('.pure-input-rounded').val() + "&api_key=dc6zaTOxFJmzC",
type: "GET",
success: function(data) {
console.log("This works too")
debugger
console.log(data[0].bitly_url) // here is where I'm having an issue!
}
});
});
*此外,我正在使用的Giphy API密钥是公共密钥。
尝试将其更改为此。 “数据”是对象中的键名,使用它两次会引起混淆。
success: function(response) {
//console.log("This works too")
//debugger
console.log(response.data[0].bitly_url);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.