I want to delete the record using ajax.
view
@foreach( $products as $product )
{{ $product->code
-
Your problem is here:
var dataId = $('#btnDeleteProduct').attr('data-id');
You are only going to get the first one, because you are using a duplicate id on all buttons.. So an id sizzle query will get you the first one.
You will see this if you dd($id) in your delete controller. It's always the id of the first. You can get the data-id attribute by querying relative to event.target.
You will want to use the debugger; statement inside your call back to test this, but the query should be something like:
$(e.target).attr('data-id');
or
$(this).attr('data-id');
The event target should be the button that was clicked, and you set the data-id on that button, so you just need to query it via the event.
- 热议问题