ajax动态更新dynatable 表格里面的数据

前端之家收集整理的这篇文章主要介绍了ajax动态更新dynatable 表格里面的数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
HTML代码
<!doctype html>
<html>
<head>
<Meta charset="utf-8">
<title>无标题文档</title>
<script src="vendor/jquery-1.7.2.min.js"></script>
<script src="jquery.dynatable.js"></script>
<link  rel="stylesheet"  href="jquery.dynatable.css" >
</head>
<body>
<script>
$(document).ready(function() {
	var mytable= $("#dynatable");
    setInterval(function() {	
  $.ajax({
      url: "do.PHP",success: function(data) {
          myRecords = $.parseJSON(data);
          mytable.dynatable({
              dataset: {				  
                  records:myRecords
              }
          });
		    mytable.data('dynatable').settings.dataset.records=myRecords;
		 mytable.data('dynatable').dom.update();		
		   console.log(data);
      }
  });
    },1000);
});

</script>
<table id="dynatable">
  <thead>
  <th>test1</th>
    <th>test2</th>
      </thead>
  <tbody>
  </tbody>
</table>
</body>
</html>

服务端PHP代码


<?PHP 
$response = array();
 $response [] = array(
        "test1" => "AAAA".time(),"test2" => "BBBB".time()
		   );

echo json_encode($response);
?>



其实这样更新也是可以的


$(document).ready(function() {
    setInterval(function() {
        $.ajax({
            url: "myStuff.PHP",success: function(data) {
                console.log(data);

                var myRecords = $.parseJSON(data);

                var dynatable = $('#dynatable').dynatable({
                    dataset: {
                        records: myRecords
                    }
                }).data('dynatable');

                dynatable.settings.dataset.originalRecords = myRecords;
                dynatable.process();
            }
        });
    },3000);
});
原文链接:https://www.f2er.com/ajax/164099.html

猜你在找的Ajax相关文章