[英]PHP - post method without reloading or refreshing page
On the first div I have a label that welcome visitor and a " next button ". 在第一个div上,我有一个欢迎访问者的标签和一个“ 下一步”按钮 。 On the second div I have a " msg textbox " and a " send button ".
在第二个div上,我有一个“ msg文本框 ”和一个“ 发送按钮 ”。 On the third div I have a " thanks label ".
在第三个div上,我有一个“ 谢谢标签 ”。
when I click on the next button the first div disappear and the second shows(with js): 当我单击下一步按钮时,第一个div消失,第二个显示(带有js):
function gotosend() {
$('#div2').show();
$('#div1').hide();
$('#div3').hide();
}
When I click on the send button the message is send, the second div disappear and the third shows (also with js): 当我单击发送按钮时,消息已发送,第二个div消失,第三个显示(也使用js):
function gotothanks() {
$('#div3').show();
$('#div2').hide();
$('#div1').hide();
}
but my problem is when the msg is send, the page was refreshed and returning to the first div. 但我的问题是,发送味精时,页面已刷新并返回到第一个div。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Survey</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function gotosend() {
$('#div2').show();
$('#div1').hide();
$('#div3').hide();
}
function gotothanks() {
$('#div3').show();
$('#div2').hide();
$('#div1').hide();
}
</script>
</head>
<body>
<div id="div1" class="div1" >
<td>
"some survey information that appears to to usr"
</td>
<br>
<a href="#" name="next button" class="next button" onclick="gotosend()">Next</a>
</div>
<div id="div2" class="div2" >
<input name="msg textbox" id="msg textbox" class="msg textbox"type="text" placeholder=" your message" maxlength="200">
<br>
<a href="#" name="send button" class="send button" onclick="gotothanks()">Send</a>
</div>
<div id="div3" class="div3" >
<td>
"Thanks ,your message has been sent !"
</td>
</div>
</body>
<?php
if(isset($_POST['send button'])){
$smg .= "Msg".$_POST['msg textbox']."\n";
$smg .= "\n\n";
$snd = "myemail@gmail.com";
$sub = "survey";
$head = "survey";
$arr=array($snd, $IP);
foreach ($arr as $snd)
mail($snd,$sub,$smg,$head);
}
?>
This is the expected behavior. 这是预期的行为。 In order to make a request without refreshing the page you'll need to use AJAX (asynchronous JavaScript & XML).
为了在不刷新页面的情况下发出请求,您需要使用AJAX(异步JavaScript和XML)。 You can read more about AJAX at http://www.w3schools.com/ajax/default.asp .
您可以在http://www.w3schools.com/ajax/default.asp上阅读有关AJAX的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.