welcome
searched on forum problem interested in couldn't found.
i have php & html code:
$admid = $row['id']; // id of admin form mysql
echo'[x]';
i need function delete admins table. know how can php, i'd without reload page.
when click on [x] wanna id of admin (the php while loop displays 5 admins). every admin have [x] sign.
if id normal string e.g id="test", easy: $('test').click(function() {});
but can't when id var. parsed php var js:
var x = '#'+'$admid;';
how should jquery function?
thank's help
just create hook jquery id:
<?php if (@$_post['action'] == "delete_admin") { // if deleted db echo json_encode(array("result"=>true)); exit; } $admin = array(array("adminid"=>1),array("adminid"=>2)); echo "<table>"; foreach ($admin $a) { echo '<tr> <td>admin ' . $a["adminid"] . '</td> <td><button type="button" delete-admin="' . $a["adminid"] . '">[x]</button></td> </tr>'; } echo "</table>"; ?> <script> $('document').ready(function() { $('[delete-admin]').on('click',function() { var remove = $(this).parents('tr'); var admin_id = $(this).val(); $.post('index.php',{action: 'delete_admin', admin_id: admin_id},function(data) { if (data.result === true) { remove.hide(); } },'json'); }); }); </script>
Comments
Post a Comment