Código fuente del chat interiorEscrito con ajax y jsp, el archivo js/js.js de registro de chat se puede mostrar sin actualizar la página varnbspobjvarnbspgetId = document.getElementById functionnbsp. objXMLHttp(){ nbsp;nbspnbspnbspvarnbspXmlHttpObjnbsp. =nbspfalse;nbspnbspnbspnbspif(ventana.ActiveXObject)nbsp. nbspnbspnbsp{ nbspnbspnbspnbspnbspnbspnbspnbspXmlHttpObjnbsp. =nbspNuevonbsp. ActiveXObject("MSXML2.xmlhttp.3.0"); nbspnbspnbspnbsp} nbspnbspnbspnbspnbspnbspelsenbspifnbsp. (Ventana.XMLHttpRequest)nbsp. nbspnbspnbsp{ nbspnbspnbspnbspnbspnbspnbspnbspXmlHttpObjnbsp. =nbspNuevonbsp. XMLHttpRequest();nbspnbspnbspnbsp} nbspnbspnbspnbspnbspnbspReturn nbsp. Función XmlHttpObj} nbsp. enviarMsg(auto){nbsp. obj = objXMLHttp();nbspif(!auto)//nbsp;{ nbspnbspvarnbspmyContentnbsp= nbspgetId("miTexto"). valor;nbspnbspif(miContenidonbsp;! = nbsp》)nbspnbsp{ nbspnbspnbspif (obj)nbsp. nbspnbspnbspnbspnbsp{ nbspnbspnbspnbspobj.onreadystatechangenbsp= nbspaddChatnbspnbspnbspnbspobj.open("POST","do.jsp",nbspTrue);nbspnbspnbspnbspobj.setrequestheader("Content-Type","application/x-www-form-urlencoded "; );nbspnbspnbspnbspnbspobj. (" mi contenido = " nbsp; nbsp; mi contenido); nbspnbspnbspnbspgetId("miTexto "); valor = " ";nbspnbspnbspnbspgetId("miTexto"). focus();nbspnbspnbspnbspscroll();nbspnbspnbspnbspnbspnbsp} nbspnbsp} nbspnbspelsenbspnbsp{ nbspnbspnbspalert(" nbsp; (*^__^*)nbsp; ¿Cómo sabemos que permanecerás en silencio si no nos lo dices?"); "mitexto "). valor = "Guardar silencio"; nbspnbspnbspgetId("miTexto "). focus();nbspnbsp}nbsp}nbspelse//nbsp;{nbspnbspif (obj)nbsp.
nbsp{ nbspnbspnbspobj.onreadystatechangenbsp= nbspaddChatnbspnbspnbspobj.open("POST","do.jsp",nbsptrue);nbspnbspnbspobj.setrequestheader("Tipo de contenido","aplicación/x-www-form-urlencoded;"); );nbspnbspnbspScroll();nbspnbsp} nbsp} } Funciónnbsp. AddChat()//Agregar registro de chat {nbspvarnbspDocumentnbsp. =nbsp"";nbspif(obj. readystatenbsp; = =nbsp4nbspampampnbspobj.statusnbsp= =nbsp200)nbsp. { nbspnbspdoc = obj.responseTextnbspnbspif (docnbsp!= nbsp》)nbspnbsp{ nbspnbspnbspgetId("dice "). valor = docnbspnbsp} nbsp} } funciónnbsp. getChatContent(){ nbsp; tnbsp= nbspsetInterval('sendMsg(true)', 800 } función nbsp. envío rápido(){nbsp;nbspif(getId("sendType ").value=="ctrlEnter")nbsp. { nbspnbspif(ventana . evento . tecla ctrlamp;ampwindow . evento . código de clave == 13)nbsp;nbsp{ nbspnbspnbspsend msg(false);nbspnbsp} nbsp} nbspelsenbspif(getId("sendType ").value=="enterKey") nbsp. { nbspnbspif(ventana . evento . código clave == 13)nbsp;nbsp{ nbspnbspnbspsend msg(false);nbspnbsp} nbsp} } Funciónnbsp. loginConfirm() { nbsp; if (ventana. evento. código clave == 13)nbsp { nbspnbspcheck usuario(); comprobar usuario(){nbsp;if(getId("nombre de usuario").value==nullnbsp.||nbsp.getId("nombre de usuario").value=