Let's assume PHPFile.php return random integer(X) every 2 seconds.
Now if X == 5 I would like to show an alert (client-side).
the following code will do that job :
$(function worker(){
$.ajaxSetup ({
cache: false,
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(worker, 2000);
}
});
$.ajax({
type: "GET",
url: "PHPFile.php",
success:function(result){
if (result == 5){
alert('test');
}
};
});
Now the problem is when we call this every 2 seconds it's like destroying the memory, especially if PHPFile.php(in example) has big size data.
30 Request every one minute and its counting.
So I wondering what is the best way to update client browser if a change occur, without refreshing the browser.
Maybe it's like facebook notification system.