簡體   English   中英

Giphy API-一旦我進行了AJAX調用,就無法弄清楚如何調用數據

[英]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,但這是行不通的。 請幫忙!

igphy_data

這是我的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM