I'm trying to delete a table row, my button works and my product deletes from the database, however it doesn't delete on the page until a refresh and I always get "It Failed" even tho it worked... What am I doing so wrong? seems like the "success" isn't being called.
$(".deleteProduct").click(function(){
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax(
{
url: "/eventlineitem/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token
},
success: function ()
{
console.log("it Work");
}
});
console.log("It failed");
});
Here is my html
<tr class="item{{$item->id}}">
<td class="align-center" scope="row">{{$item->product->id}}</td>
<td class="align-center">{{$item->quantity}}</td>
<td><a href="/products/{{$item->product->id}}">{{$item->product->name}}</a></td>
<td class="align-center">{{$item->warehouse_id}}</td>
<td class="align-center">{{$item->product->location}}</td>
<td><div class="switch">
<label><input type="checkbox"><span class="lever switch-col-green"></span></label>
</div></td>
<td><i class="material-icons deleteProduct" data-id="{{ $item->id }}" data-token="{{ csrf_token() }}">delete</i></td>
</tr>