title: Make script respond to an echo from PHP
body: <p>I want my AJAX script to respond to an <code>echo</code> from PHP, but it doesn't work. Here is register.php:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
    if (isset($_POST['username']))
    {
      require_once('dbconfig.php');
      $user = $_POST['username'];
      $pass = $_POST['password'];
  
      if (strlen($user) &gt; 1) 
      {
        echo '{"status":success}';
      } 
      else if (strlen($user) &lt; 1) 
      {
        echo '{"status":failed}';    
      }
    } else
      echo "Sesiunea nu mai este activa.";
  ?&gt;
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function() {
    $('#btnRegister').click(function() {
      var user = $('#username').val();
      var pass = $('#password').val();
      var posting = $.post("http://localhost/univoo/ucp/universitati/dbfunc/register.php", {
        username: user, 
        password: pass
      });
  
      posting.done(function(data) {
        if (data.status == "success") {
          alert("Succes");
        } else if (data.status == "failed") {
          alert("failed");
        };
      });
    });
  });
  </code></pre>