2015-12-10 143 views
1

我創建了一個使用php,ajax和jquery的聊天窗口。它成功地讀取和寫入一個名爲chatlog.html的文件。我製作了一個清除聊天的按鈕。它工作正常,但所有客戶的聊天都不清楚,直到有人說話。我將如何解決這個問題?清除聊天窗口

chat.php是在這裏,因爲我不能正確格式化:http://pastebin.com/AEwjeZ3w

sendchatmsg.php:

<?php 
session_start(); 

if (isset($_SESSION['username'])) { 
    $text = $_POST['cmsg']; 
    $fp = fopen("chatlog.html", "a"); 
    fwrite($fp, "<div><b>" . $_SESSION['username'] . "</b>: " . stripslashes(htmlspecialchars($text)) . "<br></div>"); 
    fclose($fp); 
} 
?> 

clearchat.php:

<?php 
    unlink("chatlog.html"); 
?> 

回答

0

你可以寫空文件當你清除它的時候。

clearchat.php:

$fp = fopen("chatlog.html", "w"); 
fwrite($fp, " "; 
fclose($fp); 
0

刷新聊天記錄在用戶的屏幕上,一旦明確聊天事件完成。

$("#clearchat").click(function() { 

    $.post("clearchat.php",function(res){  
      loadLog(); 
     }); 

});