簡體   English   中英

數據更改時運行功能

[英]Run function if data changed

我是jQuery的新手,無法弄清楚如何成功運行我在頁面中使用的腳本。 問題是,僅當我的load.php文件中有變化但我並不需要像現在這樣不斷變化時,才需要淡入和淡出文本,請幫助任何人...非常感謝!

這是我的代碼:

    $(document).ready( function(){
$('#auto').load('load.php');

refresh();

});



function refresh()
{

    setTimeout(function() {


      $('#auto').fadeOut('fast').load('load.php').fadeIn('fast');

      refresh();
       }, 2000);

   }

嘗試這個:

function refresh()
{
  setTimeout(function() {
    $.get('load.php', function(data) {
      if (data !== $('#auto').html()) {
         $('#auto').fadeOut('fast').html(data).fadeIn('fast');
      }
      refresh();
    });
  }, 2000);
}

這使請求超出load() ,並且僅淡入/淡出+如果內容不同則替換內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM