resources / views / emp-list.blade.php
<script>
$(document).ready(function(){
$(".delete").click(function(e){
e.preventDefault();
idd = this.id;
$.ajax({
type:"post",
data:{"idd":idd, "_token":"{{csrf_token()}}",'_method': 'DELETE',},
url:"{{URL::to('delete_emp')}}",
success:function(res){
location.reload();
}
});
});
});
</script>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($result as $row)
<tr>
<td>{{ $row->fname }}</td>
<td>
<a href="javascript:void(0)" id="{{ $row->id }}" class="btn btn-danger delete" onclick="return confirm('are you sure')">Delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
api / http / controller / UserController.php
public function delete_emp(Request $request)
{
$id = $request->input('idd');
DB::delete('delete from emp where id = ?',[$id]);
}
routes / web.php
Route::get('delete_emp','UserController@delete_emp');
我是laravel 5的新手现在我要在这里单击删除按钮以删除特定记录,但是当前单击删除按钮时会发生什么,我的console
中出现错误。那么,我该如何解决这个问题呢?请帮我。
谢谢