我想在 Laravel 6 中使用使用 Ajax 的表單刪除一個項目在我的路線中我有Route::group(['middleware' => 'auth'], function() { Route::get('/dashboard/desfazer-importe', 'DeleteImportController@index')->middleware('auth'); Route::delete('/dashboard/desfazer-importe/{id}', 'DeleteImportController@destroy')->middleware('auth');});我的看法div class="modal-body"> <h5>Deseja realmente desfazer esta importa??o?</h5> <input type="hidden" value="<?php $portal_id ?>" id="portal_id"> </div><div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button> <button type="button" class="btn btn-primary" id="delete" data-token="">Desfazer</button></div> 我通過隱藏的輸入獲取 id在 Ajax 中我有以下代碼function deleteImport(){ $('#delete').click(function() { let porta_id = $('#portal_id').val() $(this).prop("disabled",true); $.ajax({ type: 'DELETE', url: '/dashboard/desfazer-importe', data: { "id": porta_id, }, success: function(response) { console.log(response) }, error: function(error) { console.log(error) } }) }) }它可能在不使用表單操作的情況下刪除項目?我發送時收到此消息message: "CSRF token mismatch."
1 回答

慕森卡
TA貢獻1806條經驗 獲得超8個贊
您必須將 csrf 令牌添加到您的請求中:https ://laravel.com/docs/7.x/csrf#csrf-x-csrf-token
看起來你還有另一個問題。您必須將您的項目 ID 添加到 url。/dashboard/desfazer-importe/{id}
- 1 回答
- 0 關注
- 205 瀏覽
添加回答
舉報
0/150
提交
取消