In the past when i wanted to check a status from a database, i would create an ajax / javascript request every 30 seconds or 5 seconds to keep checking the database.
Is there a better way to do this now? Or would i still just create a loop structure to keep checking the database?
function ShowEmail(str)
{
var str='1'
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax/emails.php?q="+str,true);
xmlhttp.send();
}
setInterval("ShowEmail()",3000);
Basically what i’m doing is checking a status on an application
| John Doe | Application Name | Not Completed | March 29, 2014
If its updated in the database
change status to
| John Doe | Application Name | Completed | March 29, 2014
Its just for eye candy UI … i’m sure i can just tell the person to keep refreshing their page lol; my concern of having the javascript keep looping every 5 seconds through 30 sets of records will create memory issue on the User Computer and Server side.