0

我们有这段代码来刷新我们拥有的 DIV,包括一个请求数据的文件。当前功能运行良好,但我们需要 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>

自动刷新.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?

4

1 回答 1

2

你很接近,实际上你只是错过了$$

$是一个 ID 选择器,您应该使用document.getElements('.wall_actions')or$$('.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 是否回显某些内容)

于 2013-10-20T08:25:47.040 回答