Post request with jQuery and Laravel framework Post request with jQuery and Laravel framework ajax ajax

Post request with jQuery and Laravel framework


UPDATE: The problem is that the new CSRF-protection does not work with ajax-requests. Here is what you could do:

In your master template add a new meta tag with the current token like this

 <meta name="csrf-token" content="{{ Session::token() }}"> 

Then when sending your ajax call you add the token like this:

$.post('http://localhost:8000/ajax',    {        '_token': $('meta[name=csrf-token]').attr('content'),        task: 'comment_insert',        userID: _userID,        comment: _comment,        name: _name,        userName: _userName    })    .error(        ...     )    .success(        ...     );}


Is a simple code with javascript to send methods GET,POST,PUT,DELETE

declare header: <meta name="csrf-token" content="{{ Session::token() }}">

  function addCarrito(Urldir,paramt)        {        $(function(){         $.post(Urldir,{ _token: $('meta[name=csrf-token]').attr('content'), _method : 'PUT', data :  }, function(response){               if(response != '')                {                 console.log('good');                }            });        });    }