title: How Can I repeatedly get data from a php file till a certain condition is met?
body: <p>I have a php file that gets a word from a database randomly and json encodes it. I want to get the word using jquery but also make sure that word isn't in a list already. I'm confused on how I can repeatedly hit the server till my condition is met. Here is what I have:</p>
  
  <p>php:</p>
  
  <pre><code> &lt;?php
      $sql = "SELECT * FROM words ORDER BY RAND() LIMIT 1";
      $result = $db-&gt;query($sql);
  
      $row = $result-&gt;fetch_assoc();
      $word = $row['word'];
      echo json_encode($word);
      ?&gt;
  </code></pre>
  
  <p>Jquery function:</p>
  
  <pre><code>$(document).ready(function() {
      $("#newRound").on("click",function(){
          $.getJSON("getWord.php",function(data){
              //check here if data is already in wordsSoFar arary and if it is, get another word from getword.php
              document.getElementById("input1").style.visibility = 'visible';
              currentWord = data; //set the current work
              lives = 6; //reset lives
              tracker = 0; 
              incorrectLettersGuessed = "";
              allGuessedLetters = "";
              updateLetters();
              document.getElementById('hangman').innerHTML = '&lt;center&gt;&lt;img src="stage1.png"&gt;&lt;/center&gt;';
              createTable(currentWord);
              output.innerHTML = '&lt;center&gt;'+messages.validLetter + '&lt;/center&gt;';
              alert(currentWord);
          });
      });
  });
  </code></pre>