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 セレクターです。では 1 ドルの代わりに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 に答える