“用户正在输入消息”功能……

时间:2021-02-05 03:35:28

Just to point out I'm referring to chat systems written in PHP/jQuery where you see at the bottom 'User is typing a message...' I've tried so many methods to accomplish it but all fail, I built my own chat system written in PHP + MySQL/Ajax + jQuery.

我要指出的是,我指的是用PHP/jQuery编写的聊天系统,你可以在底部看到“用户正在输入消息……”我尝试了很多方法来实现它,但都失败了,我用PHP + MySQL/Ajax + jQuery编写了自己的聊天系统。

I'm not asking for someone to write the function for me but just to give me a little example so I can get an idea of what to do.

我并不是要求别人为我写函数,只是给我举个小例子,这样我就能知道该怎么做了。

I would greatly appreciate it, thanks in advance :)

非常感谢,谢谢!

4 个解决方案

#1


4  

Use a timer to send an AJAX request onkeyup that tells the database the user is typing, on the other side when your pulling down chat messages you can then notify the other person that they are typing.

使用计时器发送AJAX请求onkeyup,该请求告诉数据库用户正在输入,在另一边,当您拉下聊天消息时,您可以通知另一个用户正在输入。

Take a look at doTimeOut which has a great example of debouncing in javascript...

让我们来看看doTimeOut,它有一个很好的例子,就是在javascript中脱底……

http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/

http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/

#2


1  

Using JavaScript check every (lets say) 2 seconds if any key is pressed at chat window. If yes, then send an Ajax request to tell your application that user is typing something.

使用JavaScript检查每2秒,如果在聊天窗口按下任何键。如果是,那么发送一个Ajax请求,告诉应用程序用户正在输入一些东西。

#3


0  

You could to try check if your message textbox is filled with something every n seconds. If so, fire an server request to update that status between both users.

您可以尝试检查您的消息文本框是否每n秒填充一次。如果是,启动一个服务器请求来更新两个用户之间的状态。

#4


0  

Its easy, select the texbox for the chat message. Then use the jquery .keydown with the selection, then fire an ajax to php to tel user from database that other user is typing.

它很简单,为聊天消息选择texbox。然后使用jquery .keydown进行选择,然后从其他用户正在键入的数据库中向php用户发送ajax到php。

#1


4  

Use a timer to send an AJAX request onkeyup that tells the database the user is typing, on the other side when your pulling down chat messages you can then notify the other person that they are typing.

使用计时器发送AJAX请求onkeyup,该请求告诉数据库用户正在输入,在另一边,当您拉下聊天消息时,您可以通知另一个用户正在输入。

Take a look at doTimeOut which has a great example of debouncing in javascript...

让我们来看看doTimeOut,它有一个很好的例子,就是在javascript中脱底……

http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/

http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/

#2


1  

Using JavaScript check every (lets say) 2 seconds if any key is pressed at chat window. If yes, then send an Ajax request to tell your application that user is typing something.

使用JavaScript检查每2秒,如果在聊天窗口按下任何键。如果是,那么发送一个Ajax请求,告诉应用程序用户正在输入一些东西。

#3


0  

You could to try check if your message textbox is filled with something every n seconds. If so, fire an server request to update that status between both users.

您可以尝试检查您的消息文本框是否每n秒填充一次。如果是,启动一个服务器请求来更新两个用户之间的状态。

#4


0  

Its easy, select the texbox for the chat message. Then use the jquery .keydown with the selection, then fire an ajax to php to tel user from database that other user is typing.

它很简单,为聊天消息选择texbox。然后使用jquery .keydown进行选择,然后从其他用户正在键入的数据库中向php用户发送ajax到php。