Php 重写(刷新)echo语句,而不是将其与旧语句一起添加

Php 重写(刷新)echo语句,而不是将其与旧语句一起添加,php,jquery,ajax,forms,Php,Jquery,Ajax,Forms,我已经创建了一个输入,允许用户更新他/她的信息。输入显示输入的信息(我使用AJAX)。如果一切正常,问题是当用户决定更改个人信息、输入一些数据并点击“保存”时,它不会覆盖或刷新以前显示的数据,而是将其放在下面 我的观点是允许用户立即更改有关他/她的信息并立即显示,而不是将新记录与旧记录一起显示 这是我的index.php <head> <script type="text/javascript"> $(function() { $(".submit_button")

我已经创建了一个输入,允许用户更新他/她的信息。输入显示输入的信息(我使用AJAX)。如果一切正常,问题是当用户决定更改个人信息、输入一些数据并点击“保存”时,它不会覆盖或刷新以前显示的数据,而是将其放在下面

我的观点是允许用户立即更改有关他/她的信息并立即显示,而不是将新记录与旧记录一起显示

这是我的index.php

<head>   
<script type="text/javascript">
$(function() {
$(".submit_button").click(function() {
var textcontent = $("#content").val();
var dataString = 'content='+ textcontent;
if(textcontent=='')
{
alert("Enter some text..");
$("#content").focus();
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html('<span class="load">Loading..</span>');
$.ajax({
type: "POST",
url: "action.php",
data: dataString,
cache: true,
success: function(html){
$("#show").after(html);
document.getElementById('content').value='';
$("#flash").hide();
$("#content").focus();
}  
});
}
return false;
});
});
</script>
</head>
<body>


<div class="container">

<div class="main">
<form  method="post" name="form" action="">
<textarea style="width:500px; font-size:14px; height:60px; font-weight:bold;   resize:none;" name="content" id="content" ></textarea><br />
<input type="submit" id="submit"value="Post" name="submit" class="submit_button"/>
</form>
</div>
<div class="space"></div>
<div id="flash" align="left"  ></div>
<div id="show" align="left"></div>
</div>
</body>
</html>

$(函数(){
$(“.submit_按钮”)。单击(函数(){
var textcontent=$(“#content”).val();
var dataString='content='+textcontent;
如果(文本内容=“”)
{
警报(“输入一些文本…”);
$(“#内容”).focus();
}
其他的
{
$(“#flash”).show();
$(“#flash”).fadeIn(400.html('Loading..);
$.ajax({
类型:“POST”,
url:“action.php”,
数据:dataString,
是的,
成功:函数(html){
$(“#show”)。在(html)之后;
document.getElementById('content')。value='';
$(“#flash”).hide();
$(“#内容”).focus();
}  
});
}
返回false;
});
});

action.php

<?php
include('db.php');
$check = mysqli_query($conn,"SELECT * FROM user order by age desc");
if(isset($_POST['content']))
{
$content=$_POST['content'];
$ip=$_SERVER['REMOTE_ADDR'];


$query = "UPDATE user SET rain = '$content' WHERE name = 'gala'";
mysqli_query($conn,$query) or die("error querying record");
$fetch= mysqli_query($conn,"SELECT rain FROM user WHERE name = 'gala' LIMIT    1");
$result = mysqli_fetch_assoc($fetch);
}
?>


提前谢谢

在ajax成功回调中,使用jQuerys
.after()
函数。之后,将给定的html(您的div类“showbox”)附加到id为“box”的div。因此,每次单击save时,另一个div.showbox将添加到DOM中

使用jQuerys
.html()
替换已经存在的内容

替换

$("#show").after(html);


在ajax成功回调中,使用jQuerys
.after()
函数。之后,将给定的html(您的div类“showbox”)附加到id为“box”的div。因此,每次单击save时,另一个div.showbox将添加到DOM中

使用jQuerys
.html()
替换已经存在的内容

替换

$("#show").after(html);


请注意sql注入,不要在sql语句中直接使用用户输入(有关更多信息,请参阅)。请注意sql注入,不要在sql语句中直接使用用户输入(有关更多信息,请参阅)
$("#show").html(html);