Bad code if this is copy and paste - this is the problem line:
Code:
http.onreadystatechange=useHttpResponse();
The onreadystatechange method of the http object should be set to a reference of the function that you use to handle the response. That way, every time the readystate property of the http object changes (and hence, every time the onreadystatechange method is called) it will point to the useHttpResponse function.
In other words, change the above line to this ( without the () ):
Code:
http.onreadystatechange=useHttpResponse;
EDIT: A little further: right now, you are setting http.onreadystatechange to the value returned by useHttpResponse by assigning it like this:
Code:
http.onreadystatechange=useHttpResponse();
This tells the script to call that function and set http.onreadystatechange to it's return value (hence why you are getting the function called once and seeing an alert).
But by using the syntax without the () you are setting http.onreadstatechange to a method handled by the function named useHttpResponse.....
Hopefully that helps. A lot of people who have been using AJAX for a long time don't know the distinction and have just always left off the () because that's what they've always been doing.
Bookmarks