简体   繁体   中英

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.

Otherwise, use the callback of the submit function. 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? or use jquery load and and do the redirect from on load complete.

As already mentioned, wrap the redirection call in a jQuery's .submit() callback function.

Use the window.location.replace(URL) which is similar to a page redirect action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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