2017-02-26 33 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

這只是它最初,但它不會自動刷新負荷。 –