Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete button with confirm get 419 status #97

Open
nailfor opened this issue Feb 4, 2019 · 0 comments
Open

delete button with confirm get 419 status #97

nailfor opened this issue Feb 4, 2019 · 0 comments

Comments

@nailfor
Copy link

nailfor commented Feb 4, 2019

I'm try used grid with grid.js, when i'm click 'delete' button ajax try send request in my controller

class WebController extends Controller
{
    public function destroy(Request $request) 
    {
        echo 1;
    }
}

in web.php

Route::delete("$name/delete", 'WebController@destroy')->name('destroy');

request sended, but i have 419 error

This is because ajax does not send _token data with request, must be

_grids.utils.handleAjaxRequest = function (element, event, options) {
...
          var data = isForm ? obj.serialize() : {};
          data._token = $('meta[name="csrf-token"]').attr('content');
          
          $.ajax({
            method: isForm ? obj.attr('method') : obj.data('method') || 'POST',
            url: isForm ? obj.attr('action') : obj.attr('href'),
            data: data,
            beforeSend: function beforeSend() {
...

and in layout.blade.php

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

Also initialization grid.js must be

$(document).ready(function(){_grids.init()});

This prevents js running before HTML

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant