title: AJAX call in expressJS
body: <p>I can't seem to get the AJAX call correct.  There have been other QA that deal with the <code>$.ajax()</code> function but I'm trying to solve this with <code>$.post()</code>.  </p>
  
  <p>When the form button is clicked the javascript at the head is executed, which includes a <code>$.post()</code>.  The url <code>/login</code> is routed through and passed to <code>loginPost</code> function.  There a response is determined and sent back to the javascript (right?).  Instead, webpage renders the response (pass || fail).  </p>
  
  <p>Why isn't the response from the AJAX call being sent back to get processed?</p>
  
  <p>This is a simple example that I am working with to get me better acquainted to how AJAX in expressJS and jQuery work.  Any Help is greatly appreciated! </p>
  
  <p>--<strong>views/login.jade</strong></p>
  
  <pre><code>script(src='/_js/jquery-1.8.2.min.js')
  script
    $(document).ready(function(req, res) {
      $('#login').submit(function() {
      var formData = $(this).serialize();
      console.log(formData);
      $.post('/login', formdata, processData).error('ouch');
  
      function processData(data, status) {
        console.log(status);
        console.log(data);
        if (data == 'pass') {
          $('#content').html('&lt;p&gt;You have successfully loggin in!&lt;/p&gt;');
        } else {
          if (! $('#fail').length) {
            $('#formFrame').prepend('&lt;p id="fail"&gt;Incorrect login information. Please try again)&lt;/p&gt;');
          }
        }
      } //end processData
    }); //end submit
  }); //end ready
  
  div.main
  h1= title
  div#formFrame
    form(id='login', action='/login', method='POST')
  p
    label(for='username') Username:
    input(id='username', type='text', name='username')
  p
    label(for='password') Password:
    input(id='password', type='password', name='password')
  p
    input(id='button', type='submit', name='button', value='Submit')
  </code></pre>
  
  <p>--<strong>routes/index.js</strong>  </p>
  
  <pre><code>app.post('/login', loginPost);
  </code></pre>
  
  <p>--<strong>routes/loginPost</strong>  </p>
  
  <pre><code>module.exports.loginPost = function(req, res) {
      var password = 'admin'
        , username = 'user'
        , data = req.body;
  
      if (data.username == username &amp;&amp; data.password == password) {
        res.send('pass');
      } else {
        res.send('fail');
      }
  };
  </code></pre>