2017-02-26 47 views
0

我创建一个JavaScript自动刷新代码没有延迟,它目前刷新每一秒,不过他们是当你第一次加载页面的延迟。我如何将毫无延迟?refreshTable上首次

Javscript

 $(document).ready(function() { 
      refreshTable(); 
     }); 

     var firsttime = function refreshTable() { 
      setInterval(function() { 
       $.get('artist.php', function(data) { 
        $("#artistname").html(data); 
       }, 'text'); 
       $.get('title.php', function(data) { 
        $("#songname").html(data); 
       }, 'text'); 
       $.get('presenter.php', function(data) { 
        $("#presentername").html(data); 
       }, 'text'); 
       $.get('listeners.php', function(data) { 
        $("#listeners").html(data); 
       }, 'text'); 
      }, 1000); 
     } 

回答

1
$(document).ready(function() { 
     refreshTable(); 
     refreshTableAuto(); 
    }); 

    function refreshTableAuto() { 
     setInterval(refreshTable, 1000); 
    } 

    function refreshTable() { 
      $.get('artist.php', function(data) { 
       $("#artistname").html(data); 
      }, 'text'); 
      $.get('title.php', function(data) { 
       $("#songname").html(data); 
      }, 'text'); 
      $.get('presenter.php', function(data) { 
       $("#presentername").html(data); 
      }, 'text'); 
      $.get('listeners.php', function(data) { 
       $("#listeners").html(data); 
      }, 'text'); 
     } 
+0

这只是它最初,但它不会自动刷新负荷。 –