Nov 9, 2016
5
Level 12
Laravel Ajax Authentication????
Hey Fellow Developers,
I've been trying for a while (4 hours, lol) to make an ajax login on a popup modal with laravel. I can't seem to figure out how to send the request and receive it if there's a validation error and update the modal with the erorr if that's what happens at least with the out of the box scaffolding. Is it best to use the out of the box scaffolding or should I redesign the entire authentication process?
My Javascript on the pop up modal
var $submitBtn = $('#login-submit');
$submitBtn.on('click', function (e) {
e.preventDefault();
var $loginFormData = $('#login-form').serialize();
var $loginModal = $('#login-modal');
$.ajax({
type: 'POST',
url: '/login',
data: $loginFormData,
done: function (msg) {
alert(msg);
},
error: function( jqXhr ) {
if ( jqXhr.status == 422 ) {}
$loginModal.load('/ajaxloginform');
},
success: function(data) {
alert(data);
}
});
});
I'm sure this is completely wrong, any thoughts?
Level 24
1 like
Please or to participate in this conversation.