I am reading XML file using javascript then display it in my html page
it is working perfectly on FireFox.
I googled and found that it is because my file is local in my harddisk that is why Chrome and IE do not work, and Chrome gives this error
clocks.html:20 Failed to load file:///B:/Data/clocks.xml:
Cross origin requests are only supported for protocol schemes:
http, data, chrome, chrome-extension, https.
so I created a local website and added the file there
http://localhost/clocks.xml
I can access the file through that link, but when I replace clocks.xml
in my script with http://localhost/clocks.xml
ended with page is not working not even in FireFox and getting this error from FireFox
Cross-Origin Request Blocked: The Same Origin Policy disallows
reading the remote resource at http://localhost/clocks.xml.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).[Learn More]
how can I get this working in all browsers
my script here
window.onload = function() {
getClockInformation();
}
function getClockInformation() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
updateClocks(this);
}
};
xhttp.open("GET", "http://localhost/clocks.xml", true);
xhttp.send();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…