Когда я начинаю писать в текстовое поле text оно не пишется, обновляется и браузер жестко начинает лагать. Что делать? [chat.php] PHP: <?php> session_start(); header('Content-Type: text/html; charset=utf-8'); ?> <html> <head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> </head> <script type="text/javascript"> // setTimeout("window.location.reload()",3000); </script> <body> <script> $(document).ready (function ( ){ show();setInterval('show()',5000); $("#button").bind("click", function (){ var message = $("#text").val(); $.ajax ({ url: "chat.php", type: "POST", data: {message}, dataType: "json" }); }); }); function show() { $.ajax({ url: "chat.php", cache: false, success: function(html){ $("#content").html(html); } }); } </script> <div id="content"> <?php include("config.php"); if(isset($_POST['message'])){ $sql = "insert into `messages` (`message`) values ('".$_SESSION['login'].": ".$_POST['message']."')"; mysql_query($sql); } $sql = "select message from `messages` ORDER BY id desc LIMIT 10"; $res = mysql_query($sql); if($res) { while($row = mysql_fetch_object($res)) { printf("<ul type='none'><li>%s</li></ul>",$row->message); } } else { echo "<p> <b>Error: ".mysql_error()."</b> </p>"; exit(); } ?> <input type='text' id="text" name='message'> <button id="button">Saada</button> </div> </body> </html>
решил проблему закинув PHP: <?php include("config.php"); if(isset($_POST['message'])){ $sql = "insert into `messages` (`message`) values ('".$_SESSION['login'].": ".$_POST['message']."')"; mysql_query($sql); } $sql = "select message from `messages` ORDER BY id desc LIMIT 10"; $res = mysql_query($sql); if($res) { while($row = mysql_fetch_object($res)) { printf("<ul type='none'><li>%s</li></ul>",$row->message); } } else { echo "<p> <b>Error: ".mysql_error()."</b> </p>"; exit(); } ?> в отдельный файл