Hello all i am losing my mind here what is wrong with this code the setTimeout is not working. I am creating a messaging system and i send and recieve data but i want it to appear on another window of the browser here is the code
$(document).ready(function(){ $("form#chatform").submit(function(){ $.get("db.php",{ message: $("#msg").val(), action: "postmsg", }, function(data) { $("#msg").empty(); addMessages(data); }); return false; }); }); function addMessages(data) { $("#t1").prepend(data); } function updateMsg() { $.get("db.php", function(data) { addMessages(data); }); setTimeout('updateMsg()', 4000); } And this is the php code <?php // Configuration $dbhost = "localhost"; $dbuser = "root"; $dbpass = "root"; $dbname = "crisis"; header("Cache-Control: no-cache"); $dbconn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname,$dbconn); $name = $_GET['name']; $user2 = $_GET['user2']; $user = $_GET['user']; $msg = $_GET['message']; foreach($_GET as $key => $value) { $$key = mysql_real_escape_string($value, $dbconn); } if(@$action == "postmsg") { mysql_query("INSERT INTO Messages (Msg_body) VALUES ('$msg')") or die(mysql_error()); } $messages = mysql_query("SELECT From_user,Msg_body,Date_Time FROM Messages WHERE Msg_ID = LAST_INSERT_ID() ") or die(mysql_error()); while($message = mysql_fetch_array($messages)) { echo "<tbody id='tbody1'> <tr class='highlight'> <td width='30' align='center' style='color:royalblue'>"."•"."</td> <td width='70' align='left'>".$message["Date_Time"]."</td> <td width='600' align='left'>".$message["User_name"]."</td> <td width='600' align='left'></td> <td width='100' align='left'>".$message["Grp_abr"]."</td> <tr class='highlight'> <td></td> <td colspan='4'>".$message["Msg_body"]."</td></tr> </tbody>"; } ?>