gpt4 book ai didi

javascript - Prototype JS 框架 - 当定期更新程序发生更新时调用函数

转载 作者:行者123 更新时间:2023-11-28 16:36:02 25 4
gpt4 key购买 nike

如何在每次更新时调用函数?以下是我尝试过的。这不起作用。当我单独执行时,该函数本身运行良好。

new Ajax.PeriodicalUpdater('chatMessages', 'chat/receive_chat',
{
method: 'post',
parameters: {lId: latestId},
insertion: Insertion.Bottom,
frequency: 2,
decay: 2,
Onsuccess: val = function(){$('chatMessages').scrollTop = $('chatMessages').scrollHeight;}
});

最佳答案

这是一个工作示例:JSFiddle Example

var msgCount = 0;

new Ajax.PeriodicalUpdater('chatMessages', '/echo/html/', {
insertion: Insertion.Bottom,
frequency: 2,
decay: 2,
onSuccess: function() {
msgCount++;
var response = '<div class="msg">Message '+msgCount+'</div>';
response += '<div>'+bigLongString+'</div>';
$('chatMessages').innerHTML += response;
$('chatMessages').scrollTop = $('chatMessages').scrollHeight;
}
});


var bigLongString = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."

关于javascript - Prototype JS 框架 - 当定期更新程序发生更新时调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4017341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com