John Max
John Max

Reputation: 432

Prototype Js How to reset frequency in Periodical Updater

I have read the documentation of Prototype js related to Ajax Periodical Updater and made a lot of search But i still can't figure out how to reset Periodical Updater's Frequency after it reaches a predefined number.

For example suppose i want my page to take info every 10 seconds (frequency) and if it is not able to get any new results it should decay 2 (which means the frequency will be 20, 40, 80 ..) .

Question

But when it reaches a number superior or above 60 how to reset it to 10 segonds so that it will start again ? I have seen Ajax.PeriodicalUpdater#start() → undefined and Ajax.PeriodicalUpdater#stop() → undefined but there is no pratical example on how to use it with a condition

This is my original code

<script language='javascript'>

function mettreajour_periodique(span_id, url_traitement, nos_parametres, our_frequency, our_decay)
    {



    var ajax = new Ajax.PeriodicalUpdater ({success: span_id}, url_traitement, {method:'get', frequency: our_frequency, decay: our_decay,  parameters: nos_parametres, evalScripts: true});

    if(our_frequency>=20) { alert(our_frequency);  our_frequency=5; }


    }



//Now i will apply my function here

mettreajour_periodique('nombre_nouveaux_messages', 'barre_du_haut_actualise.php', '&membre=our_member', 10, 2);


</script>

Upvotes: 0

Views: 136

Answers (1)

RienNeVaPlu͢s
RienNeVaPlu͢s

Reputation: 7642

You can change the options of prototypes Ajax.PeriodicalUpdater by using the returned object:

ajax.frequency = 50;

Fiddle Source

Upvotes: 2

Related Questions