Javascript 联系人表单上的重定向问题
我不明白为什么这不会重定向时,一切看起来到位 我使用了位置/路径,但没有从主页移动 电子邮件发送,表单正常,但无法重定向到感谢页面或显示错误 下面是我的代码JS/PHP/HTML 提前谢谢,希望你能发现一些东西 JS: PHP:Javascript 联系人表单上的重定向问题,javascript,php,html,forms,contact,Javascript,Php,Html,Forms,Contact,我不明白为什么这不会重定向时,一切看起来到位 我使用了位置/路径,但没有从主页移动 电子邮件发送,表单正常,但无法重定向到感谢页面或显示错误 下面是我的代码JS/PHP/HTML 提前谢谢,希望你能发现一些东西 JS: PHP: HTML 创造 问题在于php标题重定向: header("Location: $redirect_thankyou"); 这会导致浏览器在ajax调用中加载重定向页面: $.post("hero-form.php", $("#register-form").
HTML
创造
问题在于php标题重定向:
header("Location: $redirect_thankyou");
这会导致浏览器在ajax调用中加载重定向页面:
$.post("hero-form.php", $("#register-form").serialize(),function(result){
因此,result
将包含您重定向到的页面的html内容,而不仅仅是发送的单词
您需要删除php中的header()
重定向,而是将jQuery中ajax调用所期望的内容发送回。Json更适合于此,但单个字符串也可以
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');
}
});
你应该为此得到一个错误;你发现打字错误了吗?是的。
$.post("hero-form.php", $("#register-form").serialize(),function(result){
if (mail($to, $subject, $message, $headers)) {
echo $redirect_thankyou;
die();
}
else
{
echo $redirect_error";
die();
}
$.post("hero-form.php", $("#register-form").serialize(),function(result){
if(result){
location.replace(result);
$('#hero-success-notification').addClass('show-up');
$('#hero-submit').addClass('disabled');
}
});