我试图从我的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.
}
});
}
答案 0 :(得分: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>