How can I refresh a form page after the form submits to _blank?

岁酱吖の 提交于 2019-11-28 23:38:29

Not sure why window.location.reload() doesn't work. I think it should. However, this does seem to work:

onsubmit="setTimeout(function () { window.location.reload(); }, 10)"

There are two ways to do this, one that you may not want to hear about.

FIRST:

In the form init tag, if you set action="" then the form will submit to the same page (to itself).

<form action="" method="post">

This allows you to add server-side code to the top of the page, like this (using PHP, for example):

<?php
    If (empty($_POST)===false) {
        //server side scripting to handle the submitted form
    }else{
?>
    //HTML to create/show the page with form for user input
<?php
    //Close the if statement
    }
?>

SECOND:

Use AJAX (javascript or jQuery) to "submit" the form, and then -- in the AJAX function's callback -- carry on with whatever changes you want to make to the page, including redirecting to a new page.

The accepted answer did not produce the desired results for me.

Accepted answer:
onsubmit="setTimeout(function () { window.location.reload(); }, 10)"

Changing the accepted answer from onsubmit to onclick did fix my issue;

Worked for me:
onclick="setTimeout(function () { window.location.reload(); }, 3)"

There may be undesirable results, or this may not be preferred but it performs as desired for me.

asa
location.refresh(true);

will help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!