martin182
5 months ago
922
7
General

csrf token mismatch

Posted 5 months ago by martin182

Hi, I have two ajax post requests. Every time I try to do a post request it says that there is a csrf token mismatch. In both ajax requests I included the csrf token.

example:

       $.ajaxSetup({
           headers: {
               'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
           }
       });


       $( "#session-timeout-dialog-keepalive" ).click(function() {
         $.ajax({
             /* the route pointing to the post function */
             url: '/session/regenerate',
             type: 'POST',
             /* send the csrf-token and the input to the controller */
             data: {
                 "test": "test"
             },
             dataType: 'JSON',
             /* remind that 'data' is the response of the AjaxController */
             success: function(data) {
               getExpiresAt();

             }
         });
        });

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