我想在 Laravel 6 中使用使用 Ajax 的表單刪除一個(gè)項(xiàng)目在我的路線(xiàn)中我有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> 我通過(guò)隱藏的輸入獲取 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) } }) }) }它可能在不使用表單操作的情況下刪除項(xiàng)目?我發(fā)送時(shí)收到此消息message: "CSRF token mismatch."
1 回答

慕森卡
TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個(gè)贊
您必須將 csrf 令牌添加到您的請(qǐng)求中:https ://laravel.com/docs/7.x/csrf#csrf-x-csrf-token
看起來(lái)你還有另一個(gè)問(wèn)題。您必須將您的項(xiàng)目 ID 添加到 url。/dashboard/desfazer-importe/{id}
- 1 回答
- 0 關(guān)注
- 212 瀏覽
添加回答
舉報(bào)
0/150
提交
取消