我正在创建一个基本的Php
Ajax
聊天应用程序。
当我在我自己的 PC 上的跨浏览器中使用这个基本应用程序时(意味着一次 chrome 和 Mozilla 假设两个人)工作正常。但是当我在跨 PC 上使用此应用程序时,意味着一个人正在从一台 PC 聊天,而另一个人正在从第二台 PC 聊天,那么它就无法正常工作..
问题:从一台 PC 发送聊天内容在第二台 PC 上接收,但从第二台 PC(聊天回复)发送聊天内容未接收
Ajax response is not coming using `set Interval` and browser is not refreshing..
代码 :
J查询
setInterval(function() {
$.ajax({
url: "http://192.168.1.13/naresh/ajaxchat/chatsave.php?q=getChat",
success: function(response) {
$("#ulShowChatContent").append(response);
}
});
}, 1000);
php
function getChat(){
$useremail = $_SESSION['email'];
$sqlGetUserInfo = mysql_query("select * from users where email = '$useremail'") or die(mysql_error());
if(mysql_num_rows($sqlGetUserInfo)>0){
$userInfo = mysql_fetch_array($sqlGetUserInfo);
$userId = $userInfo['id'];
$currentdate = date('Y-m-d H:i:s');
$sqlGetChatContent = mysql_query("select chat_id,chat_content,name from pvt_chat
INNER JOIN users ON pvt_chat.userid = users.id
where pvt_chat.userid != '$userId'
and receive_status = 0
and send_datetime <= '$currentdate'
ORDER BY send_datetime DESC limit 1") or die(mysql_error());
if(mysql_num_rows($sqlGetChatContent)>0) {
$resGetChatContent = mysql_fetch_array($sqlGetChatContent);
$receiveChatId = $resGetChatContent['chat_id'];
echo '<li>'.$resGetChatContent['name'].' says : '.$resGetChatContent['chat_content'].'</li>';
$sqlUpdateRecStatus = mysql_query("UPDATE pvt_chat SET receive_status = '1' WHERE chat_id ='$receiveChatId'") or die(mysql_error());
}
}
}