我正在創建一個基本的Php
Ajax
聊天應用程序。PHP Ajax聊天:數據一臺PC到另一臺電腦不發送/接收
當我在我自己的PC上使用這個基本的應用程序在跨瀏覽器(意味着在一次鉻和Mozilla假設兩個人)工作正常。但當我在跨PC使用此應用程序意味着一個人正在聊天從一臺PC和另一名男子正在聊天從第二臺PC然後它不工作..
問題:發送來自一臺PC的聊天內容正在接收第二臺PC 但是從第二PC(聊天答覆)發送聊天內容不接收
Ajax response is not coming using `set Interval` and browser is not refreshing..
代碼:
Ĵ查詢
setInterval(function() {
$.ajax({
url: "http://192.168.1.13/naresh/ajaxchat/chatsave.php?q=getChat",
success: function(response) {
$("#ulShowChatContent").append(response);
}
});
}, 1000);
腓
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());
}
}
}
PHP + MySQL對於這樣的任務是錯誤的堆棧 - 查看[Node.js + Websockets](http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial)。 – moonwave99
k先生。我會應用他們,但現在爲什麼它會造成問題? –
那麼檢查您的控制檯是否有任何錯誤並報告,我們無法得到任何線索。 – moonwave99