2016-03-21 49 views
0

我試圖從我的import.io APi獲取數據,我想在我的網站上顯示這個數據在一個無序列表中。我如何從我的import.io API獲取數據?

你能告訴如何做到這一點?

這是我到目前爲止有:

document.addEventListener('deviceready', onDeviceReady, false); 

function onDeviceReady() { 
    //console.log('device is ready'); 
    $.ajax({ 
     type: 'GET', 
     url: 'https://api.import.io/store/connector/93f9c80c-f8c1-4a5f-807c-f70f88630972/_query?input=webpage/url:http%3A%2F%2Fnuzzel.com%2FWAStatzz&&_apikey=e4fb993c758a43dda0ca9135d3b3264deebed4b302b0d342e2b3fabb2b49afc9c14493d0d53d65d0ea2a0fd19b45f6d10cda5252f76410921188d38cb4e6db8fc28527d64207329b2c86bdc5119bac97', 
     dataType: 'json', 
     crossDomain: true, 
     success: function(data) { 
      console.log(data); //The log dont show me nothing. 
     } 
    }); 
} 

回答

3

這似乎是你的API完美。

下面是如何顯示每個項目的所有headline列表的示例。

我剛剛將deviceready替換爲DOMContentLoaded,以使其在桌面上工作。

//document.addEventListener('deviceready', onDeviceReady, false); 
 
document.addEventListener('DOMContentLoaded', onDeviceReady, false); 
 
function onDeviceReady() { 
 
    //console.log('device is ready'); 
 
    $.ajax({ 
 
    type: 'GET', 
 
    url: 'https://api.import.io/store/connector/93f9c80c-f8c1-4a5f-807c-f70f88630972/_query?input=webpage/url:http%3A%2F%2Fnuzzel.com%2FWAStatzz&&_apikey=e4fb993c758a43dda0ca9135d3b3264deebed4b302b0d342e2b3fabb2b49afc9c14493d0d53d65d0ea2a0fd19b45f6d10cda5252f76410921188d38cb4e6db8fc28527d64207329b2c86bdc5119bac97', 
 
    dataType: 'json', 
 
    crossDomain: true, 
 
    success: function(data) { 
 
     var result = data.results; 
 
     var list = $('ul'); 
 
     for (var i = 0; i < result.length; i++) { 
 
      list.append('<li><b>headline</b>:' + result[i].headline + '</li>'); 
 
     } 
 
    } 
 
    }); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<ul id="result"> 
 
    
 
</ul>