Im trying to grab the url of the img in the XML file of the daily bing photo so i can set it as the src of my websites background.
This is my code:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script>
var x = new XMLHttpRequest();
x.open("GET", "http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US", true);
x.onreadystatechange = function () {
if (x.readyState == 4 && x.status == 200) {
var doc = x.responseXML;
var stock = document.getElementById("stock");
var img = doc.getElementsByTagName("url")[0].childNodes[0].nodeValue;
stocksrc.setAttribute("src", img);
}
};
x.send(null);
</script>
</head>
<body>
<img id="stock" src="#">
</body>
</html>
This is the error im having:
XMLHttpRequest cannot load http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.