我只想借助jquery的set interval和load函数来刷新div。正在使用数据库获取数据。我希望它重新加载,因为这是聊天门户
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..');
}
});
}
暂无答案!
目前还没有任何答案,快来回答吧!