亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Laravel 6 中使用 Ajax 刪除沒有表單的項目

如何在 Laravel 6 中使用 Ajax 刪除沒有表單的項目

PHP
眼眸繁星 2022-10-28 09:31:17
我想在 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}


查看完整回答
反對 回復 2022-10-28
  • 1 回答
  • 0 關注
  • 205 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號