问题
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.
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 :)
回答1:
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.
Take a look at doTimeOut which has a great example of debouncing in javascript...
http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/
回答2:
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.
回答3:
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.
回答4:
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.
来源:https://stackoverflow.com/questions/4428283/user-is-typing-a-message-function