vendredi 18 septembre 2020

If any error occurs from server-end and then login with right details it doesn't work. Shows 419 error

When I tried to log in using ajax first time with wrong credentials it hits the API but then again tried with right credentials show 419 error

Here is the code:-

$(document).on('submit', '#userLogin', function(e) {
        e.preventDefault();
        $('.s-login').html('Please wait...');
        $('.s-login').attr('disabled',true)
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.ajax({
            type: 'post',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            dataType: "json"
        })
        .done(function(data) {
                
            if(data.status==200){
                    toastr.success(data.message,"Status",{
                        timeOut: 5000,
                        "closeButton": true,
                        "debug": false,
                        "newestOnTop": true,
                        "positionClass": "toast-top-right",
                        "preventDuplicates": true,
                        "tapToDismiss": true
                    });
             }
         });
});

Tried to refresh the token also but sometimes it works and sometimes doesn't. Any ideas would be appreciated. Thank You !!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire