title: Writing if/else statement in AJAX
body: <p>I've been messing around with this application:</p>
  
  <p>gamble.php:</p>
  
  <pre class="lang-php prettyprint-override"><code>function gamble() {
      $chance = rand(1, 100);
  
      if ($chance &lt;= 40) {
          echo "win";
      } else {
          echo "lose";
      }
  }
  gamble();
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;button type="button" class="btn"&gt;Click Me&lt;/button&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>$(document).ready(function() {
      $(".buy_btn").click(function() {
          $.ajax({
              type: 'POST',
              url: 'scripts/gamble.php',
              success: function(data) {
                  if (data == "win") {
                      alert("You win");
                  } else {
                      alert("You lose");
                  }
              }
          });
      });
  });
  </code></pre>
  
  <p>Why won't this if/else statement work?<br>
  It's set out exactly like a JavaScript if/else statement should be, is it because it's jQuery/AJAX? How can I fix it?</p>
  
  <hr>
  
  <p>I also have another question:</p>
  
  <p>Inside the PHP document instead of echoing, I can return data instead.  However how do I use this returned data in AJAX?<br>
  I've tried using if/else statements to undertake dynamic events based on the returned data, however it doesn't work.</p>