I have a dynamically generated table that also have this button:
<button class="btn btn-danger btn-xs btn-delete delete-task"
value="{{$contact->id}}">delete</button>
At the end of the code I have this:
<meta name="_token" content="{!! csrf_token() !!}" />
The button triggers this:
$(document).ready(function(){
$('.delete-task').click(function(){
var contact_id = $(this).val();
$.ajax({
type: "DELETE",
url: adressbook_edit + '/' + contact_id,
success: function (data) {
console.log(data);
$("#contact" + contact_id).remove();
},
error: function (data) {
console.log('Error:', data);
}
});
});
}
Which is supposed to lead to my routes like this:
Route::delete('/adressbook_edit/{$contact_id?}',function($contact_id){
$contact = addressbook::destroy($contact_id);
return Response::json($contact);
});
I am expecting to delete the entry in the database, however I get a 404 error. The direction is apparently correct. Here is the error I get:
DELETE http://myip/adressbook_edit/2 404 (Not Found) send @ app.js:26 ajax @ app.js:25 (anonymous) @ adressbook.js:79 dispatch @ app.js:25 g.handle @ app.js:25 adressbook.js:87
Error: Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}
Adressbook.js is where the aforementioned ajax function is called.