Javascript 在重定向页面上显示成功消息
有两个页面:一个是index.php,另一个是add-name.php。add-name.php有一个采用名称的表单,在成功提交后,它将重定向到index.php页面,其中显示所有名称。 我想知道,在add-name.php页面在提交时重定向到index.php页面之后,如何在index.php页面上显示已添加名称的消息 添加name.phpJavascript 在重定向页面上显示成功消息,javascript,php,ajax,laravel,Javascript,Php,Ajax,Laravel,有两个页面:一个是index.php,另一个是add-name.php。add-name.php有一个采用名称的表单,在成功提交后,它将重定向到index.php页面,其中显示所有名称。 我想知道,在add-name.php页面在提交时重定向到index.php页面之后,如何在index.php页面上显示已添加名称的消息 添加name.php <?php if ($_SERVER["REQUEST_METHOD"] === "POST"){
<?php
if ($_SERVER["REQUEST_METHOD"] === "POST"){
$name = $_POST["name"];
addName($name); // this addName function saves the name to a
file called names.txt and index.php page
uses this file to access all the names
header("Location: index.php");
}
?>
<form action="add-name.php" method="POST">
<label for="name">Name:</label>
<input type="text" name="name" id="name">
<input type="submit" name="submitButton" value="Save">
</form>
姓名:
使用会话
addname.php
姓名:
index.php
提示:记住在标题()行之后调用exit()
,否则表单将在转发之前显示。为了实现您的目标,您可以使用cookie,也可以通过带有post字段的post请求转发。一旦index.php检测到post字段,将显示一条成功消息。@Shakil-Use session。初始化session并在addname.php
中添加一些值,然后在index.php
中检查/destory session,一种方法是使用URL参数重载index.php
,如下所示:header('Location:index.php?message=name+has+bes+added')代码>。然后在index.php
中,您将打印出在$中收到的任何内容
(如果有的话)。@RoAchterberg,嘿,这是个好主意。谢谢你的帮助。不客气。你的主意也很管用。谢谢你组织得很好的代码。@ShakilAhmed如果答案正确,请接受,以便以后其他人可以参考。