title: jQuery ajax request to return data and repeat
body: <p><strong>jQuery code</strong></p>
  
  <pre><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 is returned from the php script
  
  
          // somehow put the returned json data into a variable or return it?
          // this is where my problem is
  
  
      });
  }
  
  function doLoop() {
      request() // execute the ajax request to get data from database
  
      var items = // the returned json data from 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);
  </code></pre>
  
  <p><strong>The problem</strong></p>
  
  <p>The problem is that I can't get the ajax call to return the json data so I can put it into an array.
  This results in not being able to count how many items there are in the array and calculate the interval for the looping procedure. </p>
  
  <p>What I wish to accomplish is a repeating procedure, using setInterval, that:</p>
  
  <ol>
  <li>gets data from database with function <code>request</code></li>
  <li>put returned json data from <code>request</code> into array <code>items</code></li>
  <li>determine amount of items in array using <code>var count = items.length</code></li>
  <li>determine delay for <code>setInterval</code> using <code>var repeat = timeout * count</code></li>
  <li>process the array by displaying the items within, one at the time (this part works)</li>
  <li>after processing the entire array, return to step 1 to refresh the data. (should be no problem with setInterval)</li>
  </ol>