0

我在访问 Yahoo Boss YQL Json 响应数据中的任何对象时遇到很多问题。我将此YQL 控制台用于 Boss Search Tables

这是我所做的:

<!DOCTYPE HTML>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript"></script>
<script type="text/javascript">

var url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20boss.search%20where%20service%20%3D%22images%22%20AND%20count%3D%221%22%20AND%20q%3D%22iphone6%22%20AND%20ck%20%3D%20%22MYCONSUMER_KEY%22%20AND%20secret%3D%22MYCONSUMER_SECRET%22%3B&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";


(function showPix()
      {
          $.getJSON(url, function (data)
        {
          console.log(data);
          var myObj = data.results.bossresponse.images.results.result.clickurl;
          $.each(myObj, function ()
          {
            $('#pix').append(this);
          });
        });
      })();

</script>
</head>

<body>
    <div id="pix">
    </div>
    <button onclick="showPix();">run</button>

</body>
</html>

console.log(); 给了我一个包含图像的对象,但我无法在屏幕上显示图像。它告诉我 showPix 是未定义的。任何帮助将不胜感激。TIA

4

1 回答 1

0

我想出如下:

<html>  
      <head><title>YQL and RSS: Yahoo Top News Stories</title>  
      <style type='text/css'>  
        #results{ width: 40%; margin-left: 30%; border: 1px solid gray; padding: 5px; height: 200px; overflow: auto; }   
      </style>  
      <script type='text/javascript'>  
        // Parses returned response and extracts  
        // the title, links, and text of each news story.  
        function top_stories(o){  
          var items = o.query.results.item;  
          var output = '';  
          var no_items=items.length;  
          for(var i=0;i<no_items;i++){  
            var title = items[i].title;  
            var link = items[i].link;  
            var desc = items[i].description;  
            output += "<h3><a href='" + link + "'>"+title+"</a></h3>" + desc + "<hr/>";  
          }  
          // Place news stories in div tag  
          document.getElementById('results').innerHTML = output;    
        }  
        </script>  
      </head>  
      <body>  
        <!-- Div tag for stories results -->  
        <div id='results'></div>  
        <!-- The YQL statment will be assigned to src. -->  
        <script src='https://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20rss%20where%20url%3D%22http%3A%2F%2Frss.news.yahoo.com%2Frss%2Ftopstories%22&format=json&callback=top_stories'></script>  
      </body> 

于 2015-04-11T02:58:08.507 回答