2015-04-06 61 views
0

我有很多問題從雅虎老闆YQL Json響應數據訪問任何對象。我用這個YQL Console for Boss Search Tables無法從雅虎老闆YQL響應數據訪問對象

這裏是我做了什麼:

<!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

+0

我想通了這一點。 – Lamine 2015-04-11 02:53:45

回答

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>