Is it possible to redirect to a page when the readyState
is equal to 4?
//load the send form
if (sendRequest) {
sendRequest.open("POST", urlRequest, true);
sendRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
sendRequest.setRequestHeader("Connection", "close");
sendRequest.onreadystatechange = displayStatus;
sendRequest.send(sendData);
} else {
alert("fails"); //alert if request fails
}
}
function displayStatus() {
if (sendRequest.readyState == 4) {
alert("send");
// redirect to thank you page?
} else {
alert("send fails");
} //end readyState
}
I am anticipating not getting a status code of 200.
Therefore, on readyState
4, I would like to automatically redirect to another page after the form has been sent. A simple PHP mail function using
<?php header(location: "url"); ?>
does not seem to be effective, so I believe utilizing Ajax or JavaScript is necessary...
At present, my current setup just isn't functioning as expected. Any suggestions for a solution?