AIM: I would like to set the below function to call every 5 seconds. Using qtip.
The variable ALARM_POPUP changes every minute via a shellscript which replaces the contents on the variable.
CODE:
function popupTXT()
{
var ALARM_POPUP="Alarm Warning warning ";
$('#telecom_1').qtip({content:ALARM_POPUP,style: {name: 'dark', tip: 'topLeft'} });
};
I am using the below to call on a timer.
setInterval("popupTXT()",5000);
OUTCOME: This will only work when I refresh the browser. Any suggestions would be appreciated
That means that in order to see that change on the page, you have to call the server to get an updated value. You’re not doing that.
You could do that via
ajax. Create a server-side page that outputs the new value forALARM_POPUPas raw text (usingContent-Type: text/plain) or as JSON (usingContent-Type: application/json), and trigger anajaxcall to get the contents of that page, then update theqtipwith it. You wouldn’t wantsetIntervalfor that because with the indeterminate length of time theajaxcall would take, things would very quickly become chaotic. Instead, just initiate asetTimeoutupon completion of the previous cycle.Assuming you create an
updatealarm.xyzpage (PHP, JSP, ASP.Net, whatever) that outputs the currentALARM_POPUPvalue as plain text, that would look something like this:About your original
setIntervalcall: It’s best not to pass strings intosetIntervalorsetTimeout; that’s basically doing aneval, and it’s neither necessary nor a good idea. Instead, pass in a function reference (e.g., the function’s name, without()calling it), as above.Re your comment below:
I’ve only done a little PHP, but I believe it would look like this:
Or if you prefer to use a variable to make it easier for your
sedscript: