I have to fetch data from a RSS feed but the problem is that there is no Access-Control-Allow-Origin header to permit us to read data.
I have tried:
function createCORSRequest(method, url){ var xhr = new XMLHttpRequest(); // if ("withCredentials" in xhr){ if (xhr.withCredentials == true){ xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined"){ xhr = new XDomainRequest(); xhr.open(method, url); } else { xhr = null; } return xhr; } function fetchData() { var request = createCORSRequest("get", "http://example.com/data"); if (request){ // request.onload = function() { // console.log(request); // }; request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { console.log(request.responseText); } }; request.send(); } }
But it still has this error:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
I have also tried Ajax but still not working. Is there any other way?
Please note that we are not allowed to use jQuery or any other plug-ins and framework. It has to be written only in JavaScript. Please don't ask why as it is a topic that even I can't answer.
No comments:
Post a Comment