I am trying to create an instant messaging site. Every ten seconds I want a javascript/ajax script to check if there are new messages. I thought that I could have a php page output 1 if there are. I have done the php coding, but can not get the javascript side to work. I have tried using $.get and am having a bit of trouble. Any help would be greatly appreciated.
Here is my ajax code:
var check;
function checkForMessages() {
$.get("/checkmsg.php", function(data) {
if(data == 1) {
alert("There is a new message");
}
});
}
check = setInterval(checkForMessages, 10000);
My php code always outputs 1 for testing purposes