Welcome Guest, Not a member yet? Register   Sign In
Fetch data in a selected table row
#11

The problem is in this line of your script:
Code:
$('#ppmpsupplies').on('click', 'tr', edit_item( <?php echo $item->id ?> ));

If you echo a php value in a script section of your page, it is done when the page is outputted by php. This happens only once, so the value of $item->id is the last $item->id php recognizes.
It's better to add a data-id property to each table row (or the button that will trigger AJAX).
Once you start your AJAX action, you can refer to the data-id property of the selected row.
Reply
#12

(06-26-2017, 11:28 PM)Wouter60 Wrote: The problem is in this line of your script:
Code:
$('#ppmpsupplies').on('click', 'tr', edit_item( <?php echo $item->id ?> ));

If you echo a php value in a script section of your page, it is done when the page is outputted by php. This happens only once, so the value of $item->id is the last $item->id php recognizes.
It's better to add a data-id property to each table row (or the button that will trigger AJAX).
Once you start your AJAX action, you can refer to the data-id property of the selected row.
Yes sir,
That's the code above given by paradinight. The problem now is the error I mentioned above. When I try to switch the parameters (id, element) the functionality of delete works but still the error undefined appears. Thanks for the time.
Reply
#13

Code:
callback: function(item, id) {
                              var id = $(this).closest('tr').data('id');
                               delete_item(this,id);
                               return true;
                           }
Reply




Theme © iAndrew 2016 - Forum software by © MyBB