I have a page that calls a javascript function every second using
setInterval():
...
<body onload="setInterval('UpdateMessages(1);', 1000 );">
...
In UpdateMessages(), I create an AJAX XMLHttpRequest object and send
the request (with open() and send()), and I make sure to set the
onreadystatechange function.
However, the onreadystatechange function is called twice the first
second the page is run, where the xmlhttp object readyState variable
is 2 and then 4, and then each of the following seconds it is called 4
times, where the readyState variable is 4, then 4, then 2, and then 4
again. What is going on? I want to be able to execute some code when
the AJAX request is complete (i.e. when the readyState is 4) but it is
then executed 3 times because I'm getting a readyState of 4 three
times! I also checked the status variable of the xmlhttp object, and
it's always 200.
If you want the code, ask. Thanks.