Hi, I'm encountering a very strange problem with calling send() of a XMLHttpRequest object periodically. The send() will submit to a php page (silently), this page will fetch some data in the database, echo the data (in plain text format) and then delete the data. The client side will receive the echoed plain text and should receive it once time, but when the send() is called the second time (and later times), the deleted text is still received, unless I reload the page.
I think there is something wrong with how AJAX works. Here is a snippet of my code:
function getMsg() {
if(aCyclePassed) {
aCyclePassed = false;
var receiver = (XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttpRequest") ;
receiver.open("GET", "http://localhost/chatting.php?u=currentUser", true) ;
receiver.onreadystatechange = function() {
if(receiver.readyState ==4 && receiver.status ==200) {
var msg = receiver.responseText ;
aCyclePassed = true;
if(msg != "") chatBox.value += msg + "\n";
}
};
receiver.send();
}
setTimeout("getMsg()", 1000);
}
The chatting.php has nothing special than getting the variable u from client, select some text (message) from database, echo it and then delete it from database to make client fetch and display it only one time, but as I said, it seems not to be deleted (in fact it was) until I reload the client page.
Could you help me out please? This is the first online chatting application using PHP of mine, thank you very much!