I am trying to communicate with an API (http://labs.skanetrafiken.se/api.asp) from a react app.
However I keep getting blocked
var url = 'http://www.labs.skanetrafiken.se/v2.2/neareststation.asp?x=55.720504899999995&y=13.1927948'
$.ajax({
type: "GET",
url: url,
async: true,
dataType : 'xml',
crossDomain:true,
success: function(data, status, xhr) {
console.log(data);
}
});
Receives the response:
XMLHttpRequest cannot load http://www.labs.skanetrafiken.se/v2.2/neareststation.asp?latitude=55.720504899999995&longitude=13.1927948.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://stackoverflow.com' is therefore not allowed access.
However when I try the same request from my terminal like this
curl "http://www.labs.skanetrafiken.se/v2.2/neareststation.asp?x=55.720504899999995&y=13.1927948&R=1000"
I get exactly the response I am looking for. How can I circumvent this? It would be nice to not have to set up a server with the only purpose of curl
ing the API.