2013-10-20 56 views
0

我們有這段代碼來刷新我們擁有的DIV,包括一個請求數據的文件。目前的功能工作得很好,但我們希望mootools遷移。將函數從jQuery轉換爲Mootools

JS代碼:

<script> 
jQuery.noConflict(); 
(function(jQuery) { 
    jQuery(function() { 
     jQuery(document).ready(function() { 
      // First initial refresh onLoad 
      jQuery(".wall_actions").fadeOut("fast").load("auto-refresh.php").fadeIn("fast"); 
      // Use now with Interval - 10 seconds 
      var refreshId = setInterval(function() { 
       jQuery(".wall_actions").fadeOut("fast").load('auto-refresh.php').fadeIn("fast"); 
      }, 5000); 

      jQuery.ajaxSetup({ 
       cache: false 
      }); 

     }); 
    }); 
})(jQuery); 
</script> 

<div class="wall_actions"> 
<!-- other code --> 
</div> 

我們試圖用這種方法沒有成功遷移。

<script language="javascript"> 
var request = new Request({ 
    url: 'auto-refresh.php', 
    method: 'get', 
    update: 'refresh-me', 
    onComplete: function(response) { 
     $('.wall_actions').set('html',response); 
    } 
}) 

var doRefresh = function() { 
    request.send(); 
}; 

doRefresh.periodical(5000); 
</script> 

自動refresh.php

<?php 
$page = "auto-refresh"; 
include "header.php"; 

$actions_array = $actions->actions_display(0, $setting['setting_actions_actionsperuser']); 
$smarty->assign_by_ref('actions', $actions_array); 
include "footer.php"; 
?> 

我們如何使用jQuery的功能,使請求但MooTools的?

+3

投票重新公開帳戶接受的答案。 –

回答

2

您近距離,實際上您錯過了$$

$是ID選擇器,您應該使用document.getElements('.wall_actions')$$('.wall_actions');而不是$('.wall_actions').set('html',response);中的一美元。


如果你想有淡出/中,你可以試試這個:

var request = new Request({ 
    url: 'auto-refresh.php', 
    method: 'get', 
    update: 'refresh-me', 
    onComplete: function (response) { 
     el.set('tween', { 
      onComplete: function() { 
       el.set('html', response).fade('in') 
      } 
     }); 
     el.fade('out'); 
    } 
}) 

var doRefresh = function() { 
    request.send(); 
}; 

window.addEvent('domready', function() { 
    el = $$('.wall_actions'); 
    doRefresh.periodical(5000); 
}); 

我不知道你的HTML,但看看這個Fiddle
(順便說一句,仔細檢查,你的PHP確實回聲的東西)

+1

謝謝塞爾吉奧,就像一個魅力! –