title: Displaying login error on same page when using a class (php)
body: <p>I have a form to login</p>
  
  <pre><code>    &lt;div class="fade_bg"&gt;
          &lt;div class="actionDiv"&gt;
              &lt;form id="login_form" action="./classes/login/Authenticator.php" method="post"&gt;
                  &lt;p&gt;username: &lt;input type="text" name="username" /&gt;&lt;/p&gt;
                  &lt;p&gt;password: &lt;input type="password" name="password" /&gt;&lt;/p&gt;
                  &lt;p&gt;
                      &lt;input type="submit" name="adminLogin" value="Log in" id="adminLogin" /&gt;
                      &lt;input type="submit" name="cancelLogin" value="Cancel" id="cancelLogin" /&gt;      
                  &lt;/p&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Notice the form action is './classes/login/Authenticator.php.' The PHP script is by itself with no HTML or anything. </p>
  
  <p>What I want is for an error message to display inside</p>
  
  <pre><code>   &lt;div class="actionDiv"&gt;
  </code></pre>
  
  <p>If the user enters an empty form or the wrong credentials. I've tried using AJAX, but it didn't work.</p>
  
  <p>The login itself works. I just need to print the errors.</p>
  
  <p>Here is the AJAX I used:</p>
  
  <pre><code>            $('#adminLogin').on('click', function() {
                  $.ajax ({
                      type: 'post',
                      url: './classes/login/Authenticator.php',
                      dataType: 'text',
                      data: $('#login_form').serialize(),
                      cache: false,
                      success: function(data) {
                          if(data == 'invalid credentials')
                              $('body').html(data);
                          else
                              $('.fade_bg').fadeOut(200);
                      },
                      error: function(msg) {
                          alert('Invalid username or password');
                      }
                  });
              });
  </code></pre>