Jump to content

HttpRequest readyState doesn't change


Iven

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();
            }
            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 by Iven
Link to comment
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 comment
Share on other sites

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)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...