显示特定时间的弹出窗口,然后使用php重定向到另一个页面
To display a popup for specific time and then redirect to another page using php
当我提交表单时,我想要显示一个jquery对话框(不是警报),显示特定时间的成功消息,然后在该时间结束后它应该重定向到一个新页面。请不要把这个问题标记为重复,我知道这个问题之前已经回答过了,但是没有一个给我想要的结果。这是我的html代码-
<form action="submit.php" method="POST">
Name:<input type="name" id="name" />
Age:<input type="age" id="age" />
<input type="submit" name="save" />
</form>
这是我的submit.php代码-
<?php
include('db.php');
$sql ="INSERT INTO details(`name`) VALUES ('".$_POST["name"]."','".$_POST["age"]."')";
if ($conn->query($sql) === TRUE) {
/*here i want to display the dialog and then redirect to new page i.e.-header('Location:enter.php')*/
header('Location:enter.php');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
我已经尝试了onsubmit=popup();
,但是这并没有给我确认表单已经提交。
function popup(){
$("#mess").dialog({});
setTimeout(wait, 3000);
}
这可能会让你开始:
delayTime = 2000; //milliseconds
$('form').submit(function() {
$('#myMessage').fadeIn();
setTimeout(function() {
$('#myMessage').fadeOut();
}, delayTime);
//Submission continues after timeout
});
#myMessage {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: black;
opacity: 0.8;
z-index: 999;
display: none;
}
#myMsgDlg {
position: relative;
top: 50px;
width: 60vw;
height: 60vh;
margin: 0 auto;
color: yellow;
border: 1px solid orange;
overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="myMessage">
<div id="myMsgDlg">
<h3>Any HTML at all can be in here</h3>
<img src="http://placekitten.com/300/100" />
</div>
<!-- #myMsgDlg -->
</div>
<!-- #myMessage -->
<form action="submit.php" method="POST">
Name:
<input type="name" id="name" />Age:
<input type="age" id="age" />
<input type="submit" name="save" />
</form>
如果您希望在表单提交后显示确认消息,您的代码应该如下所示:
$('#submitme').click(function() {
var nam = $('#name').val();
var age = $('#age').val();
if (nam == '' || age == '') {
alert('Please complete all fields');
}
$.ajax({
type: 'post',
url: 'submit.php',
data: 'nm=' + nam + '&ag=' + age
}).done(function(d) {
if (d == 'success') {
$('#myMessage').fadeIn();
setTimeout(function() {
$('#myMessage').fadeOut();
}, 1500, function() {
window.location.href = 'enter.php';
});
} else {
alert(d);
}
}); //END done function
}); //END submitme.click
#myMessage {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: black;
opacity: 0.8;
z-index: 999;
display: none;
}
#myMsgDlg {
position: relative;
top: 50px;
width: 60vw;
height: 60vh;
margin: 0 auto;
color: yellow;
border: 1px solid orange;
overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="myMessage">
<div id="myMsgDlg">
<img src="http://placekitten.com/300/150" />
<h3>Any HTML at all can be in here</h3>
</div>
<!-- #myMsgDlg -->
</div>
<!-- #myMessage -->
<div id="myDiv">
Name:
<input type="name" id="name" />Age:
<input type="age" id="age" />
<input id="submitme" type="button" />
</div>
你的PHP现在是:
<?php
include('db.php');
$sql ="INSERT INTO details(`name`) VALUES ('".$_POST["name"]."','".$_POST["age"]."')";
if ($conn->query($sql) === TRUE) {
echo 'success';
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
相关文章:
- 通过javascript重定向html传递php变量
- PHP-如何重定向到同一页面并更改DOM's
- 如何在一页网站中使用PHP重定向到一个页面
- 当达到codeigniter/tank auth会话超时时,在ajax调用中处理php重定向
- 使用GoogleMapApi保存标记-重定向到.php页面
- php中的脚本重定向是递归的
- PHP表单提交和重定向
- 在AJAX调用中获取重定向的php页面名称
- 在php中不运行java脚本的情况下重定向页面
- php重定向到一个空白页面
- 在php中htaccess重定向url后,无法加载css和js
- 用户在文本框中输入一个数字,并根据使用 PHP 输入的数字重定向到另一个网页
- 我的 PHP 网址不会重定向
- 表单处理后 PHP 重定向
- 在 PHP 中创建模式警报而不是页面重定向验证
- 在发布表单输入时,我可以重定向到一个新的php文件吗
- Facebook 登录重定向 PHP/Javascript 不起作用
- 如何重定向PHP登录到登录用户直接进入ASPX网站
- 如何重定向PHP页面与参数到新的选项卡或窗口
- 重定向PHP文件,不管url后面键入什么