Skip to content

Instantly share code, notes, and snippets.

@craigmarvelley
Created December 20, 2012 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigmarvelley/4348760 to your computer and use it in GitHub Desktop.
Save craigmarvelley/4348760 to your computer and use it in GitHub Desktop.
$.ajax('login', {
success: function (response) {
var csrf = $('<div/>').append(response).find('input[name="_csrf_token"]').val();
if (!csrf) {
throw 'Failed to parse CSRF value';
}
$.ajax('login_check', {
type: "POST",
data: {
_username: $('#username').first().val(),
_password: $('#password').first().val(),
_csrf_token: csrf
},
success: function () {
$('#login').modal('hide');
},
error: function (xhr) {
var data = $.parseJSON(xhr.responseText);
$('.login-error').empty().append(data.message);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment