2017-07-31 19 views
-1

我正在使用以下脚本重定向到我想要的页面。我正在尝试在模式上提交表单后重定向到另一个页面

<script> 
    document 
    .getElementById("register-form") 
    .addEventListener("submit", function(e) { 
    e.preventDefault(); 
    window.location.href = "wallet.php"; 
     }); 
</script> 

问题是:如果我删除了e.preventDefault();表单被提交但没有重定向到页面,如果我包含它的表单不提交但重定向到页面wallet.php

请帮助我想提交表单并重定向到wallet.php

+0

提交表单后,您还可以使用PHP的header()函数进行重定向。 – Lalit

+0

您不能通过常规表单提交表单(打开另一个页面)***和***一次重定向到另一个页面。您必须通过AJAX *提交表单*(并等待该请求正确完成),然后*然后*重定向。 – deceze

回答

1

形式提交与阿贾克斯,使用jQuery:

$("form").on('submit', function(e){ 
    $.post("form-submit.php", $(this).parent("form").serialize(), 
     function(){ 
      window.location.href = "wallet.php"; 
     } 
    ); 
    e.preventDefault(); 
}); 

可能更容易使用

header("location: wallet.php"); 

将其重定向形式,submit.php(更换form-submit.php通过您的表单处理程序名称。)

+0

header(“location:wallet.php”);在不在模式中的表单上工作,我需要的解决方案是在模态上的表单,当我提交表单标题(“location:wallet.php”);被忽略。 –

+0

好吧,你的意思是“模态”的iframe?因为使用window.location.href可能会更复杂一点。 – Adder

相关问题