Retrieving data with cross-domain requests

Retrieving data with cross-domain requests
0

#1

Hey guys,

I’m having trouble trying to make a script that gets the source code of a website in a different domain. I tried two requests, one with ajax and one with CORS, both found online with a little search. But none of them are working because the server I’m trying to access doesn’t allow it. It also doesn’t have an API :confused:

Ajax:

$.ajax({
url: 'http://www.cresesb.cepel.br/index.php?section=sundata',
     success: function(data) { 
     console.log(data); 
     }
});

I get the following error:

XMLHttpRequest cannot load http://www.cresesb.cepel.br/index.php?section=sundata. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.

So, since I have no way of putting that header on the resource server, I can’t get any data by this method?
Is there a different way of doing this?


p.s: There is an API about solar radiation, but they only have data for the US, and all the coordinates I need to consult are in south america. https://developer.nrel.gov/docs/solar/solar-resource-v1/ . If anyone knows a good and free one that also has info for different countries it would be great!


#2

You can use www.crossorigin.me or JSONP usually to treat these sort of things, but I do not understand what you are trying to do. The link you posted is not sending you any json data, it is sending you html, how do you expect to get anything in an ajax request?