我使用php
&几乎完成了我的聊天应用程序ajax
函数。
现在的问题是,当对方用户从文本区域触发keyup()
函数时,如何显示“打字...”(文本)。
我的工作结构: -
chat.php
<?php
// unique.html is created for each individual chat , just name is stored in database.
//For eg :- Two user_id's(5,4) combined together forming 54.html ..& so on
echo '<div id="mychat_box">
//old content of chat/messages are loaded from an unique.html file here ..
//working fine
</div>
<textarea id="usermsg" ><textarea>
<input type="submit" id="submitbutton">';
?>
Ajax函数
$('#submitbutton').click(function(){
$('#usermsg').val();
//Content is posted to post.php via ajax
//working fine
});
function Loadlog() {
// This function loads/refresh the contents
//(renders content from unique.html) inside the div mychat_box
via setInterval() , 10 seconds.
}
post.php
<?php
//content is accepted from the ajax call & posted to the unique.html file .
//also some information is collected & stored to database.
//Working fine
?>
上面的过程工作正常,最后需要在相反的用户触发前面提到的keyup() function
时动态添加“打字...”文本(ajax?)。
任何人都可以解释它是如何实现的?或者用一些伪代码/文章/教程解释它背后的逻辑?
如有必要,会更详细地发布代码。