function setTimers() { timeID = window.setTimeout( "updateAll()", refreshRate ); }
每一个user都由一个username和一个GUID来唯一标识。
publicvoid AddUser(string id, string user) { //make sure user name does not exist already if( !UserExists( user ) ) { //add user to users list users.Add( id, user ); //display a notification message to all users chat.Add( this.MakeServerMessage(string.Format( joinedfmt, user ) )); } }
<script type="text/javascript"> sniffBrowserType(); //Shows loading.. screen showLoadScreen(); //Set the javascript timer and //loads user list and messages setTimers(); setFocus('mytext'); </script>
当用户键入一些信息并回车时,就会调用下面的函数:
<input type="text"class="mytext" id="mytext" onkeydown="captureReturn(event)"> // Capture the enter key on the input box and post message function captureReturn( event ) { if(event.which ||event.keyCode) { if ((event.which ==13) || (event.keyCode ==13)) { postText(); returnfalse; } else{ returntrue; } } } function postText() { rnd++; //Clear text box first chatbox = getElement( "mytext" ); chat = chatbox.value; chatbox.value =""; //get user GUID from url userid = location.search.substring( 1, location.search.length ); //construct Ajax Server URL url ='Server.aspx?action=PostMsg&u='+ userid +'&t='+ encodeURIComponent(chat) +'&session='+ rnd; //Create and set the instance //of appropriate XMLHTTP Request object req = getAjax(); //Update page with new message req.onreadystatechange = function(){ if( req.readyState ==4&& req.status ==200 ) { updateAll(); } } req.open( 'GET', url, true ); req.send( null ); }