arrays - jQuery ajax request to return data and repeat -


jquery code

var seconds = 6; var timeout = seconds * 1000;  function request() {     $.ajax ({         url: "getdata.php",         datatype: "json"     }).done(function(data) {         console.log(data); // check if json data returned php script           // somehow put returned json data variable or return it?         // problem       }); }  function doloop() {     request() // execute ajax request data database      var items = // returned json data function request()     var count = items.length;     var repeat = count * timeout;      $(items).each(function(idx, text) {         $("#text").queue(function(next) {             $(this).html(text);             next();         }).delay(timeout);     }); }  setinterval(function() {     doloop(); }, repeat); 

the problem

the problem can't ajax call return json data can put array. results in not being able count how many items there in array , calculate interval looping procedure.

what wish accomplish repeating procedure, using setinterval, that:

  1. gets data database function request
  2. put returned json data request array items
  3. determine amount of items in array using var count = items.length
  4. determine delay setinterval using var repeat = timeout * count
  5. process array displaying items within, 1 @ time (this part works)
  6. after processing entire array, return step 1 refresh data. (should no problem setinterval)

var seconds = 6; var timeout = seconds * 1000; var repeat;  function doloop() {     $.ajax ({         url: "getdata.php",         datatype: "json"     }).done(function(data) {         var items = data;         var count = items.length;         repeat = count * timeout;          $(items).each(function(idx, text) {             $("#text").queue(function(next) {                 $(this).html(text);                 next();             }).delay(timeout);         });         settimeout(doloop, repeat); // use settimeout() instead make sure  //script won't trigger before finishing previous job.     }); }  $(document).ready(doloop); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -