javascript - 将函数从 jQuery 转换为 Mootools

标签 javascript jquery ajax function mootools

我们有这段代码来刷新我们拥有的 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?

最佳答案

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

$ 是一个 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 是否回显某些内容)

关于javascript - 将函数从 jQuery 转换为 Mootools,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19473954/

相关文章:

javascript - 使用来自两个或多个框架的 CSS 主题

javascript - 将 Javascript 确认消息框标签从"is"重命名为“继续”

jquery - Bootstrap 工具提示未显示

javascript - 无法分配内存,无法创建子进程 : Do I need to queue the PHP-image requests?

javascript - 如何使 .replace(/./g, '_' ) 处理空格异常(exception)情况?

javascript - jQuery:如何加入选定元素的集合?

javascript - 使用 xmlhttprequest 对象在两个文本框中显示值?

javascript - $(selector).val() 不起作用

javascript - 如何始终收到使用 Github 登录的用户的电子邮件

javascript - 检索反馈表单的单选按钮值时出现问题