简体   繁体   English

完成表单操作后如何自动重新加载页面

[英]how to reload page automatically after completion of the action of the form

I want to auto-reload the page after completion of the action of the form. 我想在完成表单操作后自动重新加载页面。

The code for my form is: 我表单的代码是:

<form method="post" enctype="multipart/form-data" id="upload" action="<%=(String)request.getAttribute("base_url")%>files/upload/">

The browser will load whatever URL you specify in the action attribute. 浏览器将加载您在action属性中指定的任何URL。

If you want to reload the previous page then your server side code should output an HTTP redirect back to the previous page. 如果要重新加载上一页,则服务器端代码应将HTTP重定向输出返回到上一页。

Location: http://example.com/page/with/form/on/it/

PHP Solution PHP解决方案

Very simple solution with PHP PHP非常简单的解决方案

<?php
    if(isset($_POST['Submit']))
    {
    header("Location: http://yourpagehere.com");
    }
?>

Javascript Solution Javascript解决方案

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

Solution

Use the header() function. 使用header()函数。

To redirect to another page using this function, simply put in quotations 要使用此功能重定向到另一页,只需在引号中

'Location: $desired_file'

  • An example of a header function used to redirect to another page could be: header('Location: example.php'); 用于重定向到另一个页面的标头函数的示例可能是: header('Location: example.php'); .

For further instruction/help please see this link: http://php.net/manual/en/function.header.php 有关进一步的说明/帮助,请参见以下链接: http : //php.net/manual/zh/function.header.php

EDIT: If you are trying to send data to a page using the action attribute, you WILL be redirected to that page. 编辑:如果您尝试使用action属性将数据发送到页面,您将被重定向到该页面。 I'd like to help more but your question is not very clear. 我想提供更多帮助,但您的问题不是很清楚。

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

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