Skip to content

Instantly share code, notes, and snippets.

@keithmancuso
Last active October 6, 2016 08:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keithmancuso/29e8446ec5fa66fb2b01 to your computer and use it in GitHub Desktop.
Save keithmancuso/29e8446ec5fa66fb2b01 to your computer and use it in GitHub Desktop.
ajax login
<form method="post" action="" id="login-form" accept-charset="UTF-8">
<input type="hidden" name="action" value="users/login">
<input type="hidden" name="redirect" value="{{redirect}}">
<div class="form-group">
<label for="email">Email</label>
<input id="email" type="text" name="loginName" class="form-control">
</div>
<div class="form-group">
<label for="password">Password</label></h3>
<input id="password" type="password" name="password" class="form-control">
</div>
<div class="text-right">
<input type="submit" value="Log In" class="btn btn-primary ">
</div>
</form>
<script>
$('#loginForm').submit( function (e ) {
e.preventDefault();
var data = $(this).serialize();
$.ajax({
method: 'POST',
url: '/',
data: data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data) {
console.log('success', data);
})
.error(function(data) {
console.log('error', data);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment