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

I am trying to get data from import.io servers, but so far I have not received anything. But when I use another api from another server with the same code, I get the data. Can you tell me what I'm doing wrong.

This is working code, the problem is that I received nothing from import.io servers. but when I use another url from another service like kimonolabs, I get data from the 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'); } }); } 
+5
source share
1 answer

The problem with your request is the data type. You set dataType: 'jsonp' until you add a callback parameter, as described here . I'm not sure if the API you are requesting is ready for JSONP, but I tried with CORS and it works successfully. Therefore, if you are using jQuery 1.5+, replace your ajax request with the following parameters:

 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, look there . Hope this helps you :)

+5
source

Source: https://habr.com/ru/post/1216455/


All Articles