Jump to content

HttpRequest readyState doesn't change

Recommended Posts

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();
                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");
            xmlhttp.open("GET", "person.xml", true);


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 by Iven
Link to post
Share on other sites

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.

Link to post
Share on other sites


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)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...