Countdown function connected to ajax

I currently have an PrimeFaces <p:poll> ajax poll function that executes every 90 seconds to refresh some data. I've been asked to make this visual and I'm just wondering the quickest/lightest way of doing so?

The way I am thinking is I have two options:

  1. Create a PrimeFaces <p:poll> that executes every second, reducing a global JavaScript number variable, which when it gets to 0 then executes the ajax to refresh the data, although this could be subsceptible to processing lag?

    or

  2. Find/Build some sort of count down timer in jQuery/JS and like above execute when it's finished counting down.

Hopefully somebody has a cleaner/better method.

Answers


I think for this case, it would be better to use <p:remoteCommand instead of <p:poll.

That way you can code the countdown/display using JQuery and call the remote-command and reset the count to 90 when the count reaches 0.

<p:remoteCommand name="fetchData" action="#{...}" update="..."/>
<!-- fetchData here will be a global javascript function. --> 

RemoteCommand showcase

A problem with using <p:poll is that the poll's timer and the display timer won't synchronize.


Need Your Help

missing ';' before '<'

c++ templates

I am doing some exercises and tried to convert a simple class into a template class.

function (F1) in Javascript

javascript html

I'm trying to write a program that allows the user to enter any word and then press the button to get the result.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.