I wrote a little chat plugin that i'll need to use on my site. It works with a simple structure in HTML, like this:\[code\]<div id="div_chat"> <ul id="ul_chat"> </ul></div><div id="div_inputchatline"> <input type="text" id="input_chatline" name="input_chatline" value=""> <span id="span_sendchatline">Send</span></div>\[/code\]There's a 'click' bound event on that Span element, of course. Then, when the user inserts a message and clicks on the "Send" span element, there's a Javascript function with calls an Ajax event that inserts the message into the MySQL database:\[code\]function function_write_newchatline(){ var chatline = $('#input_chatline').val(); $.ajax ({ type: "POST", url: "ajax-chat-writenewline.php", //1: ok, 0: errore data: ({'chat_line': chatline}), dataType: "text", cache: false, success: function(ajax_result) { function_get_newchatlines(); } });}\[/code\]And, in case the message is successfully inserted into DB, it calls a function to read new lines and put them in HTML structure i posted before:\[code\]function function_get_newchatlines(){ $.ajax ({ type: "POST", url: "ajax-chat-loadnewlines.php", //1: ok, 0: errore data: '', dataType: "text", cache: false, success: function(ajax_result) //example of returned string: 'message1>+<message2>+<message3' { //explode new chat lines from returned string var chat_rows = ajax_result.split('>+<'); for (id_row in chat_rows) { //insert row into html $('#ul_chat').prepend('<li>' + chat_rows[id_row] + '</li>'); } } });}\[/code\]Note: 'ajax_result' only contains html entities, not special chars, so even if a message contains '>+<', it is encoded by the php script called with Ajax, before being processed from this JS function.Now, comes the strange behaviour: when posting new messages Opera, Firefox and even IE8 works well, as intended, like this:
But, when i open Chrome window, i see this:
As you can see, in Chrome the messages are shown multiple times (increasing the number each time, up to 8 lines per message). I checked the internal debug viewer and it doesn't seem that the "read new lines" function is called more than one time, so it should be something related to Jquery events, or something else. Hope i've been clear in my explanation, should you need anything else, let me know
Thanks, Erenor.EDITAs pointed out by Shusl, i forgot to mention that the function \[code\]function_get_newchatlines()\[/code\] is called, periodically, by a \[code\]setInterval(function_get_newchatlines, 2000)\[/code\] into Javascript. EDIT2Here's is a strip of the code from the PHP file called by Ajax to get new chat lines (i don't think things like "session_start()" or mysql connection stuff are needed here)\[code\]//check if there's a value for "last_line", otherwise put current time (usually the first time a user logs into chat)if (!isset($_SESSION['prove_chat']['time_last_line']) || !is_numeric($_SESSION['prove_chat']['time_last_line']) || ($_SESSION['prove_chat']['time_last_line'] <= 0)){ $_SESSION['prove_chat']['time_last_line'] = microtime(true);}//get new chat lines$result = mysql_query("select * from chat_module_lines where line_senttime > {$_SESSION['prove_chat']['time_last_line']} order by line_senttime asc; ", $conn['user']);if(!$result || (mysql_num_rows($result) <= 0)){ mysql_close($conn['user']); die('2-No new lines');}//php stuff to create the string//....die($string_with_chat_lines_to_be_used_into_Javascript);\[/code\]Anyway, i think that, if the problem was this PHP script, i would get similar errors in other browsers, too 



