I am building a registration form with jquery which should handle the request via Ajax. My code:
$.ajax(
{
type: "POST",
url: "http://www.example.com/register.php",
data: $("#register-form").serialize(),
cache: false,
success: function(message)
{
$("#reg_notification").html(message).fadeIn(400);
}
});
Now the register.php should either output an error if for example the email address is not valid and this will be put into the div reg_notification. If no error is made, then the user should be redirected to a "welcome page". But it is important that this page is not allways static, so in other words, I can not use a location.href
in the jquery code but want to use
header("Location: http://www.example.com")
in PHP. The problem is that the user wont be redirected but the content of www.example.com
will be put inside the div reg_notification.
I found a similar problem here: How to manage a redirect request after a jQuery Ajax call but the difference is that there they are using json which I can not use due to my server and they are also redirecting inside the javascript and not in the php file.