Forum Moderators: open
page_request.open('GET', url, false)
page_request.send(null)
someFunction(page_request)
so my questions are as follows.
Is onreadystatechange actually needed?
What are the advantages of it? and
Why do most AJAX scripts use it at all if it is not necessary?
As the name kind of implies, every time the "ready state" changes this function will be executed.
When the property readyState is 4 that means the response is complete and we can get our data.
Then the function that is repeatedly called can use the information depending on the readyState.
This basically ensures that only if the request has completed correctly your script will execute as you wish.
Del
However, 'AJAX' scripts can also run 'synchronously' (which is kinda AJAX without the 'A'?!) - in which case the script waits for a response from the server, no background processing, your script is stuck until you get a response. No need for the onreadystatechange.
page_request.open('GET', url, false) With a 3rd parameter set to false, the script seems to be opening a synchronous request - so no need for onreadystatechange in this case (AJAX without the 'A'). This needs to be true for a regular asynchronous AJAX request.
(Well, I believe that's the idea... I'm no AJAX expert!)