JQuery PeriodicalUpdater. Please Help.

JQuery PeriodicalUpdater. Please Help.

Dear Experts,  

According to Robert Fischer's JQuery-PeriodicalUpdater on GitHub, it is possible to make an Ajax call for data every so many seconds or so.

Description of the code:

Whenever page ajax.php loads, I make an Ajax request to PHP page last10entries.php that spits out the last 10 public entries on the site as an xml document. This Ajax code loops through each root XML node and retrieves the text values inside nodes Title and Body. It then returns them to the screen.

PHP front page:
http://174.52.58.221/ajax.php

Pure xml page(Request is made to):
http://174.52.58.221/xml/public/last10entries.php



The following working code does it on document ready event but, I'd like it to make it so after this document loads, it will repeat this request every 5 seconds.

Following, is my current code:

  1. $(document).ready(function(){
  2. $.ajax({
  3. type: 'GET',
  4. url: 'http://174.52.58.221/xml/public/last10entries.php',
  5. //data: { postVar1: 'theValue1', postVar2: 'theValue2' },
  6. beforeSend:function(){
  7. // this is where we append a loading image
  8. $('#ajax-panel').html('<img src="js/loading.gif" alt="Loading..." />');
  9. },
  10. success:function(data){
  11. // successful request; do something with the data
  12. $('#ajax-panel').empty();
  13. // find and loop through each root xml node...
  14. $(data).find('entry').each(function(i){
  15. $('#ajax-panel').append('Title Node: ' + $(this).find('title').text() + '<br/>'    + 'Body Node: ' + $(this).find('body').text() + '<br/>');
  16. });
  17. },
  18. error:function(){
  19. // failed request; give feedback to user
  20. $('#ajax-panel').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
  21. }
  22. });
  23. });

My question is how do I use the same code above using the PeriodicUpdater example below:

  1. $.PeriodicalUpdater('/path/to/service', {
    method: 'get', // method; get or post
    data: '', // array of values to be passed to the page - e.g. {name: "John", greeting: "hello"}
    minTimeout: 1000, // starting value for the timeout in milliseconds
    maxTimeout: 8000, // maximum length of time between requests
    multiplier: 2, // the amount to expand the timeout by if the response hasn't changed (up to maxTimeout)
    type: 'text', // response type - text, xml, json, etc. See $.ajax config options
    maxCalls: 0, // maximum number of calls. 0 = no limit.
    autoStop: 0 // automatically stop requests after this many returns of the same data. 0 = disabled.
    }, function(remoteData, success, xhr, handle) {
    // Process the new data (only called when there was a change)
    });












I would be eternally grateful if someone could post a working example using my code. Provided you understand this plugin, I believe you should be no challenge.

Thank you kindly for any help on this post.