Laravel 4 AJAX CSRF Token Mismatch (with _token) -
i'm attempting simple (soft) delete on model customized implementation of frozennode/administrator
package. whenever hit route via ajax, application throws tokenmismatchexception
.
i've tried both cookie
, file
drivers set in session
config.
i have confirmed _token
being submitted ajax request. commenting csrf
filter out altogether allows me delete record. i'm using out-of-the-box csrf
filter.
i'm using excellent sweet alert plugin, though doesn't appear related.
routes.php:
//csrf protection in forms route::group(array('before' => 'csrf'), function() { //delete item route::post('{model}/{id}/delete', array( 'as' => 'admin_delete_item', 'uses' => 'frozennode\administrator\admincontroller@delete' )); ...
blade template:
<a href="" class="btn btn-danger" id="delete-item-button" data-token="{{ csrf_token()}} "> <i class="fa fa-trash"></i> <span> delete </span> </a>
javascript:
excuse hellishness $.post what's relevant.
$('#delete-item-button').on('click', function (e) { e.preventdefault(); var token = $(this).data('token'); swal({ title: "delete record?", text: "there's no undo!", type: "warning", showcancelbutton: true, confirmbuttoncolor: "#dd6b55", confirmbuttontext: "yes, delete it!", closeonconfirm: false }, function () { $.post( window.location.pathname + "/delete", {"_token" : token}, function(){ swal({ title: "deleted!", text: "the record has been deleted.", type: "success" }, function () { window.location.href = 'http://www.example.com' })}, "json" ); }); });
any or guidance greatly appreciated.
thanks!
Comments
Post a Comment