js中,设置定时器 每隔几秒刷新一次页面数据


页面加载进来,查询  然后设置定时器 每隔五秒刷新一次页面数据
fnSearch();
var interval3=setInterval(function(){
     fnSearch();
},5000);
 

  function fnSearch(){

     searchjson.search=$(".iptsearch").val();
    $.ajax({
      url:'/movecheck/getCheckInfo',
      data:searchjson,
      type:'post',
      success:function(dt){
        fnCreateTable(dt);
        if(dt.data.length == 0){
          $('.moveinnerTbody').html('');
          var oTr = $('<tr></tr>');
          oTr.html(`
              <td colspan="7" class="">抱歉,没有查询到数据</td>
          `);
          $('.moveinnerTbody').append(oTr);
          $('#pagination').html('');
        }
      },
      error:function(dt){
        createPrompt('error','抱歉,没有查询到数据!',true);
      }
    })
  }

清除定时器,停止刷新

interval1=setInterval(fnSearch,5000);

clearInterval(interval1);

猜你喜欢

转载自blog.csdn.net/qq_42177730/article/details/81199036