利用Ajax静态刷新后台数据

时间:2022-11-15 07:27:23

<script language="JavaScript">
 window.onload = function() {
  window.setInterval(showData, 5000);//每隔5s刷新数据

  function showData() {
   var time = (new Date()).valueOf();//加个时间戳
   var xmlHttpRequest = $.post(
     "${pageContext.request.contextPath}/getData?time=" + time,
     null, function(data, textStatus) {
      var dataInfo = eval("(" + data + ")").obj;//识别jason格式
     $("#show").append(dataInfo + "<br>");
    });
  }
 }
</script>