jam*_*mil 5 javascript jquery cordova import.io
我正试图从import.io服务器获取数据,但直到现在我什么也没得到.但是当我使用相同代码的另一个api时another server,我得到了数据.你能告诉我我做错了吗?
这是工作代码,问题是我从import.io服务器得不到任何东西.但当我使用另一个服务如kimonolabs的另一个网址时,我从同一个代码中获取数据.对不起我的英文不好.我收到了这个响应代码:200
这是我的代码.
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
//console.log('device is ready');
$.ajax({
type: 'GET',
url: 'https://api.import.io/store/data/6847842b-a779-46ba-874a-d1cfdcef2e3e/_query?input/webpage/url=http%3A%2F%2Fwww.girabola.com%2F%3Fp%3Djogos%26epoca%3D62%26jornada%3D1&_user=779609bc-1bfe-4bb3-aa45-465a3fc31d9a&_apikey=MY API KEY',
dataType: 'jsonp',
success: function(data) {
console.log(data); //The log dont show me nothing.
var output = '';
//output += '<ul>';
output += '<ul data-role="listview" data-inset="true">';
output += '<li data-role="list-divider">Equipa Técnica</li>';
console.log(data);
$(data.results).each(function(index, value) {
output += '<li>' + this.casa + '</li>';
});
output += '</ul>';
$('#um').append(output).listview().listview('refresh');
}
});
}
Run Code Online (Sandbox Code Playgroud)
您的请求的问题是数据类型.您可以设置dataType: 'jsonp'当您没有添加回调参数等中描述的在这里.我不确定您查询的API是否准备好了JSONP,但我尝试使用CORS并且它成功运行.因此,如果您使用jQuery 1.5+,请使用以下选项替换您的ajax请求:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
//console.log('device is ready');
$.ajax({
type: 'GET',
url: 'https://api.import.io/store/data/6847842b-a779-46ba-874a-d1cfdcef2e3e/_query?input/webpage/url=http%3A%2F%2Fwww.girabola.com%2F%3Fp%3Djogos%26epoca%3D62%26jornada%3D1&_user=779609bc-1bfe-4bb3-aa45-465a3fc31d9a&_apikey=MY API KEY',
dataType: 'json',
crossDomain: true,
success: function(data) {
// Your code
}
});
}
Run Code Online (Sandbox Code Playgroud)
如果您想了解更多关于jQuery的AJAX选项,看看那里.我希望它能帮到你:)
| 归档时间: |
|
| 查看次数: |
382 次 |
| 最近记录: |