views:

812

answers:

1

Hey!

Anyone know if it is possible to make the PeriodicalUpdater pass the data it received to a function I assign to update the desired field?

I want to process the data I receive and then have the PeriodicalUpdater function update the field.

+3  A: 

Yes, you can pass it an onsuccess callback, just like you do for a any other AjaxRequest.

new Ajax.PeriodicalUpdater('container', '/someurl', {
  method: 'get', 
  frequency: 3, 
  decay: 2;
  onsuccess: function(response){
     myCustomFunction(response.responseText);
  }
});

function myCustomFunction(data){
  /* do something */
}

See Ajax.PeriodicalUpdater and Ajax Options.

Jose Basilio
So is it possible to prevent it from updating? I think I just need it to run the call and not insert anything because the field I need to be updated has to be updated in a very particular way
AntonioCS
You could have a hidden div and pass that as the 'container', in that way, nothing visible would be updated and you still have control of what to updated using your custom function
Jose Basilio
Nice idea. I have already changed it to ajax.request but maybe I could just update an empty div.Thanks for the idea
AntonioCS
Antonio - please accept my answer if it was helpful :-)
Jose Basilio