This could be a synchronous issue requiring an answer that your code just doesn't get.
Try using an asynchronous call instead:
Connect.open("GET", "xmlTest.xml", true);
Also, make sure you set up the correct callbacks, since now you will use async instead of synchronous code:
// Global variable scope var docX; var linjer; // Define your get function getDoc = function(url, cbFunc) { var Connect = new XMLHttpRequest(); // Perform actions after request is sent // You'll insert your callback here Connect.onreadystatechange = function() { // 4 means request finished and response is ready if ( Connect.readyState == 4 ) { // Here is where you do the callback cbFunc(Connect.responseXML); } }; // 'true' param means async, it is also the default Connect.open('GET', url, true); Connect.send(); } // Define your callback function callbackFunction = function(responseXML) { // XML file can now be stored in the global variable window.docX = responseXML; window.linjer = window.docX.getElementsByTagName("linjer"); } // And here is the call you make to do this getDoc("xmlTest.xml", callbackFunction);
To get a better understanding of all this, do some area research, closing , callbacks, and async .
source share