不用重新加载或刷新页面的post方法

PHP - post method without reloading or refreshing page

本文关键字:刷新 方法 post 新加载 加载      更新时间:2023-09-26

第一个div我有一个标签,欢迎访问者和一个"下一个按钮"。在第二个div我有一个"msg文本框"和一个"发送按钮"。在第三个div我有一个"感谢标签"。

当我点击下一个按钮,第一个div消失,第二个显示(与js):

function gotosend() {
    $('#div2').show();
    $('#div1').hide();
    $('#div3').hide();
}

当我点击发送按钮的消息是发送,第二个div消失,第三个显示(也与js):

function gotothanks() {
    $('#div3').show();
    $('#div2').hide();
    $('#div1').hide();
}

但是我的问题是当发送MSG时,页面被刷新并返回到第一个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);
}
?>

这是预期的行为。为了在不刷新页面的情况下发出请求,你需要使用AJAX(异步JavaScript)。XML)。您可以在http://www.w3schools.com/ajax/default.asp上阅读更多关于AJAX的信息。