How to fetch the value of body.data[0].images.fixed_height.url?

时间:2017-04-24 08:51:49

标签: javascript jquery html json console

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script type="text/javascript">

var xhr = $.get("http://api.giphy.com/v1/gifs/search?q=ryan+gosling&api_key=dc6zaTOxFJmzC&limit=5"); 
    xhr.done(function(data) { console.log("success got data", data); });
    </script>

This is the response body from giphy:

enter image description here

的价值

4 个答案:

答案 0 :(得分:1)

你几乎就在那儿......你为什么要开始身体?检查working example

var xhr = $.get("https://api.giphy.com/v1/gifs/search?q=ryan+gosling&api_key=dc6zaTOxFJmzC&limit=5");
xhr.done(function(data) {
  console.log( data.data[0].images.fixed_height.url);
});

答案 1 :(得分:0)

请尝试以下代码

Xhr.done (function (data) {<br>
          Console.log ("success got data", data);<br>
          // How to check with log<br>
          Console.log (data [0] .images.fixed_height.url + "");<br>
});

答案 2 :(得分:0)

从你的printcreen你需要为网址安装以下内容:

 console.log( data.data[0].images.fixed_height.url);

演示:https://jsfiddle.net/a2Lfg20g/

第一个data是响应主体,第二个data是来自响应主体的对象数组

答案 3 :(得分:0)

试试这个:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script type="text/javascript">

var xhr = $.get("http://api.giphy.com/v1/gifs/search?q=ryan+gosling&api_key=dc6zaTOxFJmzC&limit=5"); 
    xhr.done(function(data) { console.log("success got data", data.data[0].images.fixed_height.url); });
    </script>