Iven 0 Posted April 30, 2018 Report Share Posted April 30, 2018 (edited) Hello I have the following javascript code.It is suppose to execute when the html page is done loading but in stead it executes and then nothing happend (the page seems like it is loading something but nothing ever happens) Here is my code : function LoadXML() { if(window.XMLHttpRequest) { var xmlhttp = new XMLHttpRequest(); } else{ var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (this.readyState == 0) { alert("im here 0"); } if (this.readyState == 1) { alert("im here 1"); } if (this.readyState == 2) { alert("im here 2"); } if (this.readyState == 3) { alert("im here 3"); } if (this.readyState == 4) { alert("im here 4"); PopulateImages(this); } }; xmlhttp.open("GET", "person.xml", true); xmlhttp.send(); } Feels like I created an infinite loop. The alert message is for debugging purposes. I get the alert message "im here 1"(not 0,2,3,4 just 1) and then the page just keeps on loading and loading and nothing is happening. Cannot open developer tools to check what code is bugging out(if I do than no resources at yet been loaded so there is nothing I can check to try and figure out the problem). I know the code will have worked if my PopulateImages function is called but it is never called. Edited April 30, 2018 by Iven Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 30, 2018 Report Share Posted April 30, 2018 Why exactly do you think you can't use the developer tools? I would replace those alerts with console.log statements and use the console, alerts are synchronous and you may be missing something. Also, you might want to just print the value of readyState instead of doing that if block. Make sure you're also checking the status code. Quote Link to post Share on other sites
Iven 0 Posted May 1, 2018 Author Report Share Posted May 1, 2018 Hello I mean if I use developer tools there is nothing(almost like going in the developer tools of an empty page html page instead the html page also doesn't show up in network or sources tabs in developer tools) Also I started out using the console but with above problem the console is also clear nothing shows up there.I switched to alerts because it is the only indication I have of where my code is and where it stops(at readyState 1) Quote Link to post Share on other sites
john_jack 7 Posted May 1, 2018 Report Share Posted May 1, 2018 Can you post the entire code please. Or you can check this tutorial https://www.w3schools.com/xml/dom_intro.asp . Good luck Quote Link to post Share on other sites
justsomeguy 1,135 Posted May 1, 2018 Report Share Posted May 1, 2018 If you're opening the developer tools after you have the page open, you need to refresh the page. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.