lundi 1 juillet 2019

ajax post returns laravel error 500 (Internal Server Error)

I added the csrf token and it still returns that error. Unfortunately everywhere I search is just telling me to add that to my view but if I already have that what am I supposed to do from here?

<meta name="_token" content="{!! csrf_token() !!}" />

...

$('#like_unlike').on("submit", function( event ) {
            event.preventDefault();
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                }
            });
            $.ajax({
                url: '',
                type: 'post',
                data: {
                    _token : $('meta[name="csrf-token"]').attr('content'),
                    data:$('#like_unlike').serialize()
                }, // Remember that you need to have your csrf token included
                dataType: 'json',
                success: function( _response ){
                    console.log(_response)
                },
                error: function( _response ){
                    console.log('failure')
                }
            });
        });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire