Php 在表单提交中加载感谢弹出式div
我在提交时加载jQuery模式窗口时遇到问题 我想在提交时加载一个div,以感谢用户参与竞争。如果我添加a href,则div可以正常打开,如: 然而,我似乎不能使这个弹出一旦提交。我做错什么了吗 这是我的表单php代码:Php 在表单提交中加载感谢弹出式div,php,javascript,jquery,html,forms,Php,Javascript,Jquery,Html,Forms,我在提交时加载jQuery模式窗口时遇到问题 我想在提交时加载一个div,以感谢用户参与竞争。如果我添加a href,则div可以正常打开,如: 然而,我似乎不能使这个弹出一旦提交。我做错什么了吗 这是我的表单php代码: <?php if($_POST['formSubmit'] == "Submit") { $errorMessage = ""; if(empty($_POST['formName'])) { $errorMessage .= "<li&
<?php
if($_POST['formSubmit'] == "Submit")
{
$errorMessage = "";
if(empty($_POST['formName']))
{
$errorMessage .= "<li>You forgot to enter your name</li>";
}
if(empty($_POST['formTown']))
{
$errorMessage .= "<li>You forgot to enter your town</li>";
}
$varName = $_POST['formName'];
$varTown = $_POST['formTown'];
$varAge = $_POST['formAge'];
$varEmail = $_POST['formEmail'];
$varOne = $_POST['hidden-one'];
$varTwo = $_POST['hidden-two'];
$varThree = $_POST['hidden-three'];
$varFour = $_POST['hidden-four'];
$varFive = $_POST['hidden-five'];
if(empty($errorMessage))
{
$fs = fopen("mydata.csv","a");
fwrite($fs,$varName . ", " . $varTown . ", " . $varAge . ", " . $varEmail . ", " . $varOne . $varTwo . $varThree . $varFour . $varFive . "\n");
fclose($fs);
header("Location: #dialog");
exit;
}
}
?>
这是jquery代码:
<script>
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
});
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
</script>
这是我的html:
<form action="enter.php" method="post" target="_self">
<input class="submit" type="submit" name="formSubmit" value="Submit">
</form>
<div id="boxes">
<div id="dialog" class="window">
<p>Modal content here</p>
</div>
</div>
</div>
</div>
<!-- Mask to cover the whole screen -->
<div id="mask"></div>
</div>
如果您有一个提交按钮,并且没有调用preventdefault或类似的东西,那么您的表单将被发布,页面将被刷新。所以你的js代码不再被执行了。你需要做的是使用一个普通的按钮或链接,并将一个onclick事件绑定到它,它首先显示感谢弹出窗口,然后通过JavaScript“手动”提交表单。听起来你可能对你的web浏览器和web服务器之间发生的事情有点困惑 您的web浏览器正在运行一个客户端,该客户端呈现HTML/CSS并执行JavaScript。您的浏览器将向web服务器提交请求,web服务器执行PHP以生成响应
表单提交后,请求将发送到web服务器,该服务器将生成响应—通常是另一个HTML页面。这是您的感谢信应该放在的地方。不,不,我明白。我只是觉得一个弹出的“谢谢你”是最好的方式。