简体   繁体   English

自动刷新消息传递系统?

[英]Automatic refresh of messaging system?

I have a IM messaging system in place, and does allow the sending of messages, however I'm wanting to update it like every 5 seconds or so that user can see the messages on both of their accounts. 我有一个IM消息传递系统,并且确实允许发送消息,但是我想每5秒更新一次,以便用户可以在两个帐户上看到消息。

So it would be like... 就像...

User1 > sends message to User2 > function is run every 5 seconds > User2 is able to see the message with out page refresh. User1>向用户2发送消息>每5秒钟运行一次功能> User2能够看到该消息而无需刷新页面。

I was thinking it would be simple and that I would just run the functions as below: 我当时认为这很简单,并且我将只运行以下功能:

window.setInterval(function(){
    load_primary_im();
    load_secondary_im();
    num_of_extra();
}, 5000);

This worked to a certain extent. 这在一定程度上起作用。

However I did not account that this clears the textarea which the user is typing in. I was just wondering if there is anyway around this issue? 但是,我不认为这会清除用户键入的文本区域。我只是想知道是否仍然存在此问题?

I agree with the architecture comments, what you are trying to achieve sounds perfect for a node.js app, similar to this real time voting system: 我同意有关体系结构的评论,您想要实现的效果对于node.js应用来说是完美的,类似于此实时投票系统:

http://www.ibm.com/developerworks/library/wa-nodejs-polling-app/ http://www.ibm.com/developerworks/library/wa-nodejs-polling-app/

Thank for the advice however after doing a bit more messing around I have managed to do it using an array and the .load function of jquery. 感谢您的建议,但是经过一番混乱之后,我设法使用数组和jquery的.load函数来做到这一点。

function convo_refresh() {

var myArray = [21,20,19,18];   
for (i=0;i<myArray.length;i++) {
$('.convo' + myArray[i]).load('filenamehere.php .convo' + myArray[i]);   
}   
}
setInterval(convo_refresh, 5000);

All i need to do now is generate an array from the data base of conversations and I should be set. 我现在需要做的就是从对话数据库生成一个数组,并且应该设置我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM