を使用してデータを削除します..私はrun..Butに、以下の手順を行ってきた:PHP Laravel:私はそれがエラーを以下に示します削除しようとしたとき、私は、AJAXを使用してデータベースから一部のデータを削除したいアヤックス
をここFailed to load resource: the server responded with a status of 404 (Not Found)
は私のルートである:ここでは
Route::post('/delete/{id}',[
'uses'=>'[email protected]',
'as' => 'delete'
]);
はコントローラです:
public function delete($id)
{
Item::find($id)->delete();
return Redirect::back();
}
そしてここでは、私の見解のPAGでありますe:
<html>
<head>
<title> Item List</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<h3> List Of Courses </h3></br>
<table class="table table-striped table-bordered dataTable" id="example">
<thead>
<tr>
<td>Serial No</td>
<td>Title</td>
<td>Description</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<?php $i=1; ?>
@foreach($items as $row)
<tr>
<td>{{$i}}</td>
<td>{{$row->title }}</td>
<td>{{$row->description}}</td>
<td>
<button type="button" onclick="deleteItem({{ $row->id }})" id="Reco" class="btn btn-danger">Delete</button>
</td>
</tr>
<?php $i++; ?>
@endforeach
</tbody>
</table>
</div>
<script>
function deleteItem(id) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url: '/delete/'+id,
success: function(result) {
console.log(result);
}
});
}
</script>
</body>
</html>
私がやったエラーが見つかった場合は、それを見つけてもらえたらうれしいです。
データはすでに削除されているのでしょうか? –
いいえ...ノーイングが削除されました – Hola