Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jqueryajax:如何在刷新页面时保持记录不消失_Php_Ajax_Jquery - Fatal编程技术网

Php jqueryajax:如何在刷新页面时保持记录不消失

Php jqueryajax:如何在刷新页面时保持记录不消失,php,ajax,jquery,Php,Ajax,Jquery,我使用这个脚本 <script type="text/javascript"> $(function () { $(".comment_button").click(function () { var element = $(this); var boxval = $("#content").val(); var dataString = 'content=' + boxval; if (boxval == '') {

我使用这个脚本

<script type="text/javascript">
  $(function () {
    $(".comment_button").click(function () {
      var element = $(this);
      var boxval = $("#content").val();
      var dataString = 'content=' + boxval;
      if (boxval == '') {
        alert("Please Enter Some Text");
      } else {
        $("#flash").show();
        $("#flash").fadeIn(400).html('<img src="ajax.gif" align="absmiddle">&nbsp;<span class="loading">Loading Update...</span>');
        $.ajax({
          type: "POST",
          url: "update_data.php",
          data: dataString,
          cache: false,
          success: function (html) {

            $("ol#update").prepend(html);
            $("ol#update li:first").slideDown("slow");
            document.getElementById('content').value = '';
            $("#flash").hide();
          }
        });
      }
      return false;
    });
    $('.delete_update').live("click", function () {
      var ID = $(this).attr("id");
      var dataString = 'msg_id=' + ID;
      if (confirm("Sure you want to delete this update? There is NO undo!")) {
        $.ajax({
          type: "POST",
          url: "delete_data.php",
          data: dataString,
          cache: false,
          success: function (html) {
            $(".bar" + ID).slideUp('slow', function () {
              $(this).remove();
            });
          }
        });
      }
      return false;
    });
  });
</script>

$(函数(){
$(“.comment_按钮”)。单击(函数(){
var元素=$(此);
var-boxval=$(“#内容”).val();
var dataString='content='+boxval;
如果(boxval=''){
警报(“请输入一些文本”);
}否则{
$(“#flash”).show();
$(“#flash”).fadeIn(400).html('loadingupdate…');
$.ajax({
类型:“POST”,
url:“update_data.php”,
数据:dataString,
cache:false,
成功:函数(html){
$(“ol#update”).prepend(html);
$(“ol#update li:first”)。向下滑动(“慢速”);
document.getElementById('content')。value='';
$(“#flash”).hide();
}
});
}
返回false;
});
$('.delete_update').live(“单击”,函数(){
var ID=$(this.attr(“ID”);
var dataString='msg_id='+id;
如果(确认(“确实要删除此更新?没有撤消!”){
$.ajax({
类型:“POST”,
url:“delete_data.php”,
数据:dataString,
cache:false,
成功:函数(html){
$(“.bar”+ID).slideUp('slow',函数(){
$(this.remove();
});
}
});
}
返回false;
});
});
该脚本使用jquery和ajax将实时更新和删除记录结合起来


问题是当我刷新页面时,记录将消失。。重新加载页面时,如何保持显示的记录不消失

首先检查注释列表。您是否在查询中设置了任何限制,若有,则使用Order by Primary ID desc。这样它将首先显示最新记录


当您删除任何记录时,请检查它是否实际从数据库中删除。因为您没有按照给定的代码检查记录是否已实际删除。

假设您正在使用update_data.php和delete_data.php操作某些数据库,您可以使用php最初使用数据库中当前的数据呈现页面

如果不是这样,并且您没有访问该数据库的权限(可能是第三方web服务,对吧?),或者您出于任何原因不想这样做,那么您可以使用类似Saeed的cookie