Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

balistikbill's avatar

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?

0 likes
5 replies
balistikbill's avatar

Nope, couldn't find a good read about this! Thanks.

1 like
balistikbill's avatar

What site is this? Is it your site? The code4fun.io?

edoc's avatar

nope.i had happened to come across the site when I was trying to do what u r doing now

balistikbill's avatar

Dude, this read is perfect, I've been getting really annoyed at the fact that I couldn't get it to work and this is going to be very very helpful!

Just wanted to say thanks so much! @edoc

1 like

Please or to participate in this conversation.