Why, when I send a GET request using XMLHttpRequest, do I get two readyState 1?

<div id="myDiv"></div> <script> var xmlhttp = new XMLHttpRequest(); document.getElementById("myDiv").innerHTML += xmlhttp.readyState + "<br/>"; xmlhttp.onreadystatechange = function() { document.getElementById("myDiv").innerHTML += xmlhttp.readyState + "<br/>"; } xmlhttp.open("GET", "example.com", true); xmlhttp.send(); </script> 

I get this on display:

 0 1 1 2 3 4 

Why are there two 1s?

My browser is firefox 17.0.

+4
source share
1 answer

Ready states are well defined for the HTTP XML object: https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#Properties .

But the sequence of readiness states seems different for each browser, so you cannot rely on a specific sequence of states in your code.

 FF 19: 0, 1, 1, 2, 3, 4 Chrome 24: 0, 1, 2, 3, 4 Opera 12.12: 0, 1, 2, 3, 4 Safari 5.1: 0, 1, 2, 3, 4 IE 9: 0, 1, 1, 2, 3, 4 

You can test your browser here .

+1
source

All Articles