Hello,
I have a problem with a command in javascript, during an AJaX call.
I use the following code to detect when the readyState of a variable has changed so that I call another function.
Code:
myrequest.onreadystatechange=getData();
function getData() {
if (myrequest.readyState===4) {
if (myrequest.status===200) {
var text=myrequest.responseText;
alert(text);
}
}
}
The problem is that the command onreadystatechange does not work properly because the function getData() gets loaded before the readyState of myrequest has changed. What can I do to fix this?