nhayder
2 months ago
210
4
Laravel

AJAX call not working of safari but working on chrome

Posted 2 months ago by nhayder

I'm using jquery to delete a user logs, My code is working on chrome and i can remove all logs as expected but with safari i'm getting this error

{
    "message": "CSRF token mismatch.",
    "exception": "Symfony\Component\HttpKernel\Exception\HttpException",
    "file": "/Applications/MAMP/htdocs/app/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php",
    "line": 208,
    "trace": [
        ...
    ]
}

this is my jquery ajax code

        $('#deleteUserLogHistory').on('show.bs.modal', function (event) {

          var button = $(event.relatedTarget)

          var elemID = button.data('id')
          
          var modal = $(this)

          modal.find('.delete-user-Log').val(elemID)

            // delete function
            $(".delete-user-Log").click(function(){

                // get item id
                var id = $(this).val();

                // get token value
                var token = $("meta[name='csrf-token']").attr("content");

                // deleting item
                $.ajax(
                    {
                        url: "/admin/logs/user/delete/"+id,

                        type: 'DELETE',

                        data: {

                            "id": id,

                            "_token": token,

                        },

                        success: function (){

                            // reload Page
                            location.reload();
                            
                        }

                    });

            });

        })

This is the method on my controller

    public function destroyUserRecords($id)
    {

        if (Gate::denies('activities.delete')) {
            
            return abort(403);
        
        }

        $delete = Activity::where('user_id', '=', $id);

        $delete->delete();

    }

Can anyone see a problem with me code, Before safari is not working?

Please sign in or create an account to participate in this conversation.