Problems with redirect on contact form

假如想象 提交于 2019-12-02 13:04:42

The problem is your php header redirect:

header("Location: $redirect_thankyou"); 

This causes the browser to load the redirected page in your ajax call:

$.post("hero-form.php", $("#register-form").serialize(),function(result){

So result will contain the html contents of the page you have redirect to and not just the word sent.

You need to remove the header() redirects in php and instead send the content back that your ajax call in jQuery is expecting. Json would be better suited for this, but a single string should work as well.

php

if (mail($to, $subject, $message, $headers)) {
    echo $redirect_thankyou; 
    die(); 
} 
else 
{ 
    echo $redirect_error"; 
    die(); 
} 

javascript

$.post("hero-form.php", $("#register-form").serialize(),function(result){
    if(result){
       location.replace(result);
       $('#hero-success-notification').addClass('show-up');
       $('#hero-submit').addClass('disabled');
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!