i've create a chat in ajax, but i still have some problem that i can't recognize. When the page is loaded, the php load all the opened chat and relative mex, then there's an addmex ajax function: when the user hits enter it's called passing this.value and the cod_chat. The ajax function send these data to the php, which insert them into the db and add the last mex into the chat. Every X seconds an update function is called, to update the chat. It all works until it gets to the addmex function: the php works, because it add the mex into the db, but for some reason it refresh the page. Could i use RTMP?
This is the code of the form:
<input type='text' class='chat_input' value='write something' onkeydown='if (event.keyCode == 13){addmex(this.value); this.value='';}'/>
and this is the code of the ajax function (don't worry about the php variables because this function is loaded by echo):
function addmex(mex)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","addmex.php?cod_contatto="+' . $cod_contatto . '+"&mex="+mex,false);
xmlhttp.send();
document.getElementById("messaggi_' . $cod_contatto . '").innerHTML+=xmlhttp.responseText;
}
I set Async as false because it respond slowly, and if i set true works only with some alert that let the server part complete. Any idea?