This API request does not get anything other than a status code of '0' and I cant figure out whats wrong with it. The console.log on the browser reads "response for preflight is invalid (redirect)" but if I simply add the website url to my browser I can access it. There must be something wrong with the way I am making my request but I can't figure it out. Here is the code.
var authKey = "http://en.wikipedia.org/w/api.php?action=centralauthtoken&format=json";
var xhr = new XMLHttpRequest();
xhr.open("GET", authKey, true);
xhr.setRequestHeader('Api-User-Agent', 'http://s.codepen.io');
xhr.send();
var xmlDocument = xhr.response;
console.log(xhr.status);
console.log(xhr.statusText);
I've also changed 'http' to 'https' but I still get '0' only this time on the console you see "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://s.codepen.io' is therefore not allowed access."
I'm unsure if its the syntax, the way I have structured the request or what but after two days of trying different solutions on stackoverflow and google I've still gotten nowhere. Incase anyone wants to see the actual website i'm having difficulty with its on here http://codepen.io/Ramins01/pen/rxExKw