Vote count:
0
A PHP script I have written currently uses a redirect:header to move you onto the next page.
It is a login form, and if successful it takes you to register-succes.php. if unsuccessful (things weren't filled in correctly) it stores an error message in a session and reloads you back into register-form.php to try again.
Originally this was working absolutely fine, because all the pages where separate (like register-success.php was it's own page with full HTML).
But I have since changed it so that you stay on the same page and the main div is loaded in via AJAX. This means that using a redirect no longer works.
This, at present is the successful redirect of the form:
if(register($email_address, $username, $password) === true){
// Sends an email
send_email($email_address);
$succeeded = true;
header("Location: register-success.php?username=$username");
exit;
}
Instead of the simple redirect, how can I have this just reload register-succes.php through AJAX, something like below, but in PHP?
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("login-register-wrapper").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","register-success.php",true);
xmlhttp.send();
Aucun commentaire:
Enregistrer un commentaire