So when I run the following code in w3schools live code test feature, the output is the same as seen in the code snippet (4) but when I run it with files that I have locally stored, the output is just 'test' instead of 4. Any ideas why or how to fix?
<!DOCTYPE html>
<html>
<body>
<p id="demo">test</p>
<script>
var count = 0;
var xhr = new XMLHttpRequest();
xhr.open( 'GET', 'https://dl.dropbox.com/s/bsb8g518r23y0wf/books.xml?dl=0', true );
xhr.onreadystatechange = function ( e ) {
if ( xhr.readyState == 4 && xhr.status == 200 )
document.getElementById("demo").innerHTML = xhr.responseXML.getElementsByTagName( "title" ).length ;
};
xhr.send( null );
//document.getElementById("demo").innerHTML = xhr;
</script>
</body>
</html>
In w3schools code testing and local files, it is 'books.xml' instead of the dl.dropbox link, same in the local files which refers to a books.xml file that I have stored in the same file as the HTML and js
xhr.open( 'GET', 'books.xml', true );