Я пытаюсь обновить div только с помощью заданного интервала и функции загрузки JQuery. Данные загружаются в базу данных. Я хочу его перезагрузить, так как это портал чата
chat1.php код, который я пытаюсь загрузить в #chat:
<?php
include('db.php');
$ment=$_GET['mentor_name'];
$stu=$_GET['stu'];
?>
<?php
if (isset($_POST['stu_send'])){
$msg_student=$_POST['msg_student'];
$sqls=mysqli_query($con,"insert into chats (student_email,mentor_email,content,sender_id) values ('$stu','$ment','$msg_student','$stu')");
echo '<a href = "chat1.php?stu=<?php echo $stu; ?> & mentor=<?php echo $ment; ?>"></a>';
}
$chat=mysqli_query($con,"select content,sender_id,c_date from chats where student_email='$stu' AND mentor_email='$ment'");
while($row_con=mysqli_fetch_array($chat)){
$sender_id=$row_con['sender_id'];
$cont=$row_con['content'];
$c_date=$row_con['c_date'];
echo $sender_id.": ";
echo $cont . "<br/>";
echo $c_date;
// echo date("h:i:sa");
// echo date("Y/m/d");
echo "<hr>";
}
?>
Обновить код:
setInterval(refreshMessages, 1000);
function refreshMessages() {
$.ajax({
url: 'chat1-1.php',
type: 'GET',
dataType: 'html',
success: function(data) {
$('#chat').html(data); // data came back ok, so display it
},
error: function() {
$('#chat').prepend('Error retrieving new messages..');
}
});
}
Я пробовал, но ничего не получил
Пожалуйста, ознакомьтесь с подготовленными операторами и внедрением sql






Вы отлаживали свой код?