Laravel 8 crud using ajax: Uncaught ReferenceError: data_id is not defined
Laravel 8 crud using ajax: Uncaught ReferenceError: data_id is not defined
所以我正在尝试使用 ajax 进行 CRUD。添加没问题,但编辑不是因为这个错误
Uncaught ReferenceError: data_id is not defined
这是我的触发按钮:
@foreach($admin_quests as $quest)
//some codes
<button class="btn btn-success" type="button" id="editBtn" data_id="{{ $quest->id }}">Edit</button>
@endforeach
这是控制器:
use Response;
//some codes
public function edit(AdminQuest $adminQuest)
{
return Response::json($adminQuest);
}
这是脚本:
$('body').on('click','#editBtn', function(){
$('#addUpdateModal').modal('show');
$('#modalTitle').html("EDIT QUEST");
console.log($(this).attr('data_id'));
//THIS IS WHERE THE PROBLEM STARTS
//admin_quest/{admin_quest}/edit
$.get("{{ route('admin_quest.index') }}" + '/' + data_id + '/edit', function(data){
//some codes
});
我忘记放了
data_id = $(this).attr('data_id');
定义 data_id.
所以我正在尝试使用 ajax 进行 CRUD。添加没问题,但编辑不是因为这个错误
Uncaught ReferenceError: data_id is not defined
这是我的触发按钮:
@foreach($admin_quests as $quest)
//some codes
<button class="btn btn-success" type="button" id="editBtn" data_id="{{ $quest->id }}">Edit</button>
@endforeach
这是控制器:
use Response;
//some codes
public function edit(AdminQuest $adminQuest)
{
return Response::json($adminQuest);
}
这是脚本:
$('body').on('click','#editBtn', function(){
$('#addUpdateModal').modal('show');
$('#modalTitle').html("EDIT QUEST");
console.log($(this).attr('data_id'));
//THIS IS WHERE THE PROBLEM STARTS
//admin_quest/{admin_quest}/edit
$.get("{{ route('admin_quest.index') }}" + '/' + data_id + '/edit', function(data){
//some codes
});
我忘记放了
data_id = $(this).attr('data_id');
定义 data_id.