title: How to use jquery/ajax data for passportjs
body: <p>If I send a login request using the form fields <code>action="/login", method="post"</code>, it works just fine. Similar to  the code available <a href="https://github.com/scotch-io/easy-node-authentication/tree/local" rel="nofollow">here</a> or <a href="https://github.com/maxdow/passport-local/tree/master/examples/express4" rel="nofollow">here</a>.</p>
  
  <p>But if instead, if I send the same information using <code>jquery/ajax</code>, then passport just doesn't seem to work. There is no actual login happening via passport, but the ajax call gives a misleading success message.</p>
  
  <p>The below isn't working. Though I get "login success" message, login hasn't really happened.</p>
  
  <pre><code>$('#login_button').click(function () {
  
      var email = $('#email').val();
      var password = $('#password').val();
      alert ('email/pass:' + email + ", " + password);
  
      $.ajax({
          type: "POST",
          url: "/login",
          data: { email: email , password: password },
          dataType: 'html'
      })
              .done(function () {
                  console.log("http request succeeded");
                  alert("login success");
              });
  });
  </code></pre>
  
  <p>I need to use the <code>ajax</code> method, so that I can do something useful on the client side, after successful login. E.g. start <code>socket.io</code>.</p>
  
  <p>Please help. My modified code is available here: <a href="https://github.com/ubersensei/passport-ajax-login/tree/e87ddf0a9f56c8c27ed86c499959567bed28ce87" rel="nofollow">my-modified-code</a></p>