Witam chce aby strona się nie odświeżała tylko jeden element, ale wyskakuje mi undefined.
<form method="post" id="send" action="send.php" >
<div id="content">
<textarea id="chatwindow" style="margin: 0px; width: 500px; height: 160px;" readonly>
<?php
require('get.php');
?>
</textarea>
</div>
<input id="text" name="tekst" type="text" size="50" maxlength="80" onkeyup="keyup(event.keyCode);" placeholder="Napisz coś">
<input type="button" name="send" hidden="hidden" value="Wyslij" style="cursor:pointer;border:1px solid gray;"><br><br>
</form>
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
$("#send").submit(function(){
$.ajax({
type: "POST",
url: "send.php",
data:"tekst="+$("#tekst").val(),
success: function(){
$("#chatwindow").load("get.php");
$("#tekst").val('');
}})
var textarea = document.getElementById('chatwindow');
textarea.scrollTop = textarea.scrollHeight;
return false;
});
window.setInterval(function(){
$("#chatwindow").load("get.php");
}, 1000);
});
var textarea = document.getElementById('chatwindow');
textarea.scrollTop = textarea.scrollHeight;
</script>
I taki kod PHP
$u = $_SESSION['user'];
$tekst = addslashes(mysql_escape_string($_POST['tekst']));
if ($tekst == NULL) {
} else {
if ($tekst == "/cls") {
mysql_query("DELETE FROM chat");
mysql_query("INSERT INTO `chat`(`usrname`, `color`, `tekst`, `chattime`) VALUES ('System',0,'Chat został wyczyszczony przez Moderatora',now())");
} else {
mysql_query("INSERT INTO `chat`(`usrname`, `color`, `tekst`, `chattime`) VALUES ('$u',0,'$tekst',now())");
}
}
header("Location: gra.php");