• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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-27-2017, 12:28 AM)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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.