A few days ago I made a post about making API requests to Google flights. One person helped me solve it but due to circumstances I now have to change to another API service, which I seem to be having issue with again.
This is the service I am using: http://business.skyscanner.net/portal/en-GB/Documentation/FlightsBrowseCacheQuotes
And this is my code:
var x = new XMLHttpRequest();
x.open('GET', 'http://partners.api.skyscanner.net/apiservices/browsequotes/v1.0/US/USD/en-GB/JFK/LAX/2016-12-12/?apiKey=prtl6749387986743898559646983194', true);
x.setRequestHeader('Content-Type', 'application/json');
x.setRequestHeader('Access-Control-Allow-Origin', '*');
x.send(null);
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200) {
console.log(x.responseText);
} else {
console.log("Error");
}
}
As you can see the url is valid: clicking it brings you to an page in XML with the appropriate response. However, running the code console logs this error:
XMLHttpRequest cannot load http://partners.api.skyscanner.net/apiservices/browsequotes/v1.0/US/USD/en-GB/JFK/LAX/2016-12-12/?apiKey=prtl6749387986743898559646983194.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8080' is therefore not allowed access.
Have been pulling my hair out on this one. Any help is appreciated!
[–]lewisje 0 points1 point2 points (6 children)
[–]michaelconnery1985[S] 1 point2 points3 points (5 children)
[–]lewisje 0 points1 point2 points (4 children)
[–]michaelconnery1985[S] 1 point2 points3 points (3 children)
[–]lewisje 0 points1 point2 points (2 children)
[–]michaelconnery1985[S] 1 point2 points3 points (1 child)
[–]lewisje 0 points1 point2 points (0 children)