Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Ayuda con chat

Estas en el tema de Ayuda con chat en el foro de Frameworks JS en Foros del Web. Hola a todos, Estoy haciendo un chat pero tengo algunas dificultades, es un servicio al cliente por medio de un chat, es decir de la ...
  #1 (permalink)  
Antiguo 19/09/2007, 12:08
Avatar de chidomen  
Fecha de Ingreso: enero-2005
Ubicación: aquí
Mensajes: 380
Antigüedad: 19 años, 3 meses
Puntos: 0
Pregunta Ayuda con chat

Hola a todos,

Estoy haciendo un chat pero tengo algunas dificultades, es un servicio al cliente por medio de un chat, es decir de la parte cliente el usuario usa el chat para comunicarse con otra persona, esa persona es el administrador. El codigo hasta aqui va bien. Por parte del administrador es que puede ver a los diferentes clientes que se hayan conectado. Y puede entrablar diferentes conversaciones dependiendo el numero de clientes.

Mi problema es el siguiente, cuando envio el mensaje para escribir en el chat, tengo que refrescarla cada cierto tiempo (2 segundos), y lo hago por medio de: setTimeout('getChatTextA();',2000); //Refresh our chat in 2

y me refresca todas las ventanas que tengo abiertas pero me cambia la informacion a desplegar.

Como le puedo hacer para solo refrescar la pantalla a la que mande un mensaje, o como puedo hacerle para que

Este es el codigo:

Código HTML:
<script language="JavaScript"  type="text/javascript">
			var lastMessage = 0;
			var mTimerA;
			
           function sendChatTextA() {
			if(document.getElementById('txtmessage').value == '') {
					alert("You have not entered a message !");
					return;
				}
				if (sendReq.readyState == 4 || sendReq.readyState == 0) {
					
					sendReq.open("POST", '/yazadmin/php/getUsers.php?last=' + lastMessage, true);
					sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					sendReq.onreadystatechange = handleSendChatA; 
					var param = 'message=' + document.getElementById('txtmessage').value;
					param += '&nick=' + document.getElementById('nick').value;
					param += '&tech_user=' + document.getElementById('tech_user').value;
					param += '&chat_id=' + document.getElementById('chat_id').value; 

					sendReq.send(param);
					document.getElementById('txtmessage').value = '';
				} else {
				  alert("there's been a error, try again.!"); 
				}	
			 }
			//When our message has been sent, update our page.
			function handleSendChatA() {
				//Clear out the existing timer so we don't have 
				//multiple timer instances running.
				clearInterval(mTimerA);
				getChatTextA();
			}	
			
			//Gets the current messages from the server
			function getChatTextA() {
				if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
					
					receiveReq.open("GET", '/yazadmin/php/getChat.php?mode=1&chat_id=' + document.getElementById('chat_id').value, true);
					receiveReq.onreadystatechange = handleReceiveChatA; 
					receiveReq.send(null);
				}			
			}		 
			 
			 //This functions handles when the user presses enter.  Instead of submitting the form, we
			//send a new message to the server and return false.
			function blockSubmit() {
				sendChatTextA();
				return false;
			}
			
			//Function for handling the return of chat text
			function handleReceiveChatA() {
				if (receiveReq.readyState == 4) {
					
					var admin_div = document.getElementById('div_admin');
					var xmldoc = receiveReq.responseXML;
					var message_nodes = xmldoc.getElementsByTagName("message"); 
					var n_messages = message_nodes.length
					for (i = 0; i < n_messages; i++) {
						var user_node = message_nodes[i].getElementsByTagName("user");
						var text_node = message_nodes[i].getElementsByTagName("text");
						//var time_node = message_nodes[i].getElementsByTagName("time");
						admin_div.innerHTML += '<font class="chat_user">' + user_node[0].firstChild.nodeValue + '-- '+ n_messages +'</font>&nbsp;---&nbsp;<br>	';
						//chat_div.innerHTML += '<font class="chat_time">' + time_node[0].firstChild.nodeValue + '</font><br />';
						admin_div.innerHTML += '<font class="chat_text">' +text_node[0].firstChild.nodeValue + '</font><br />';
						admin_div.scrollTop = admin_div.scrollHeight;
						lastMessage = (message_nodes[i].getAttribute('id'));
					}
[B]//mTimerA = setTimeout('getChatTextA();',2000); //Refresh our chat in 2 seconds[/B]
				}
			}
</script> 

Espero haberme dado a entender, si no, haganmelo saber para volver a intentarlo. No busco que me digan por medio de codigo como hacerle, si no por logica como deberia de funcionar.

Espero que alguien pueda ayudarme ya que me esta dando dolores de cabeza esto

Saludos a todos!
__________________
.. simplemente soy un mexicano apasionado ..
guasanericonsul.com
  #2 (permalink)  
Antiguo 28/09/2007, 08:46
 
Fecha de Ingreso: mayo-2004
Ubicación: Guadalajara, Jalisco, México
Mensajes: 724
Antigüedad: 19 años, 11 meses
Puntos: 6
Re: Ayuda con chat

Hola, tambien estoy desarrollando un chat, creo estoy poco más avanzado que tu en desarrollo, al grado de, empezar a trabajar en mensajes privados en divs, mi version es muy parecida a la que tienes, con algunas diferencias..

Te dejo mi email, para que te pongas en contacto conmigo.
[email protected]

Saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:24.