Javascript 将函数从jQuery转换为Mootools
我们有这段代码来刷新一个DIV,包括一个请求数据的文件。当前函数工作正常,但我们需要mootools迁移 JS代码:Javascript 将函数从jQuery转换为Mootools,javascript,jquery,ajax,function,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(".wa
<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>
jQuery.noConflict();
(函数(jQuery){
jQuery(函数(){
jQuery(文档).ready(函数(){
//首次初始刷新加载
jQuery(“.wall_actions”).fadeOut(“fast”).load(“auto refresh.php”).fadeIn(“fast”);
//现在使用,间隔10秒
var refreshId=setInterval(函数(){
jQuery(“.wall_actions”).fadeOut(“fast”).load('auto-refresh.php').fadeIn(“fast”);
}, 5000);
jQuery.ajaxSetup({
缓存:false
});
});
});
})(jQuery);
我们尝试使用此方法进行迁移,但没有成功
<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>
var请求=新请求({
url:“auto refresh.php”,
方法:“get”,
更新:“刷新我”,
未完成:功能(响应){
$('.wall_actions').set('html',response);
}
})
var doRefresh=函数(){
request.send();
};
doRefresh.期刊(5000);
自动刷新.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";
?>
如果不使用MooTools,我们如何使用jQuery函数发出请求?您已经接近了,实际上您只是错过了
$
$
是一个ID选择器,您应该使用document.getElements('.wall\u actions')
或$('.wall\u 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,但请查看此内容。
(顺便说一句,请仔细检查您的php是否有响应)根据已接受的答案投票重新打开。