I've looked into several Stack Overflow posts, read what Mozilla wrote about HTTP access control (CORS), followed the HTML5 Rocks tutorial 'Using CORS' and read Nicholas C. Zakas' article called 'Cross-domain Ajax with Cross-Origin Resource Sharing', but I still haven't found the solution to my problem.
I'm trying to load XML data from another domain/origin (that provided me with an account to get access to their API), but I keep getting this error:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Strangely, I'm getting this error in Chrome and Firefox, but not in Safari (I don't know about IE).
This is my code:
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method, url, true);
xhr.withCredentials = true;
} else if (typeof XDomainRequest != "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
var request = createCORSRequest("GET", "http://webservices.ns.nl/ns-api-avt?station=ut")
if (request){
request.onload = function(){
document.getElementById("test").innerHTML = request.responseText;
};
request.send();
}
Can anybody help me out?