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

これだけの負荷には、それが自動的に更新されません。 –