简体   繁体   English

如何提交表格,然后重定向到个性化的“谢谢”页面?

[英]How to submit a form and then redirect to a personalized thank you page?

        $("#new_note").submit();
    window.location.href='./thankyou.php?usr_id=<?php echo $_SESSION['pid'>';

Hi, this is a simple code for submitting a form and then redirect to a thank you page. 嗨,这是提交表单然后重定向到“谢谢”页面的简单代码。 It actually does the redirecting part but the form is not submitted 它实际上执行了重定向部分,但未提交表单

I guess it redirects before the submit is completed, how can it be avoided? 我想它会在提交完成之前重定向,如何避免?

不要通过JavaScript进行重定向,而是将您提交表单的页面重定向到“感谢”页面。

As @ThiefMaster says, you should redirect on the server side. 正如@ThiefMaster所说,您应该在服务器端重定向。

Otherwise, use the callback of the submit function. 否则,使用的回调submit功能。 It makes sure the submit is performed. 确保提交已执行。

$('#new_note').submit(function() {
    window.location.href = // your code
})

I'm not familiar with php but cant you redirect the page from the submit handler itself, after the process completed? 我不熟悉php,但是在处理完成之后,您不能从提交处理程序本身重定向页面吗? or use jquery load and and do the redirect from on load complete. 或使用jquery load并从负载完成重定向。

As already mentioned, wrap the redirection call in a jQuery's .submit() callback function. 如前所述,将重定向调用包装在jQuery的.submit()回调函数中。

Use the window.location.replace(URL) which is similar to a page redirect action. 使用window.location.replace(URL) ,它类似于页面重定向操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM