Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get data from my import.io api servers

I'm trying to get data from import.io servers but till now I got nothing. But when I use another api from another server with same code I get the data. Can you tell me what I'm doing wrong.

This is working code, the problem is that I got nothing from import.io servers. but when I use another url from another service like kimonolabs I get data from this same code. Sorry my bad english. I got this response code: 200

This is my code.

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');
        }
    });
}
like image 638
jamil Avatar asked Mar 30 '15 12:03

jamil


Video Answer


1 Answers

the problem of your request is the datatype. You set dataType: 'jsonp' while you didn't add a callback parameter like described here. I'm not sure if the API that you're querying is JSONP-ready but I tried with CORS and it works successfully. So if you use jQuery 1.5+, replace your ajax request with these options:

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
        }
    });
}

If you want to know more about jQuery ajax options, have a look there. I hope it will help you :)

like image 160
Yacine Rezgui Avatar answered Oct 29 '22 15:10

Yacine Rezgui