简体   繁体   English

PHP获得唯一ID

[英]PHP get unique id

With help from this forum I wrote the code: 在这个论坛的帮助下,我编写了代码:

<?php
 if ($_POST['action'] == "delete_admin") {
       echo json_encode(array("result"=>true));
       exit;
 }

 while($row = mysql_fetch_array($query9)) {
  $res = array(array("adm"=>$row['id']));

  foreach($res as $a) {
   echo'<div id="adAdmListItem">&bull;&nbsp;&nbsp;&nbsp;'.$row['admin'].'
    <span id="adRemoveAdm">
     <span delete-admin="'.$a['adm'].'">[x]</span>
    </span>
   </div>
  }
 }
?>

And jquery: 和jQuery:

$('[delete-admin]').on('click',function() {
    var remove = $(this).parents('div#adAdmListItem');
    var admin_id = $(this).val();

    $.post('index.php',{action: 'delete_admin', admin_id: admin_id},function(data) {
        remove.hide();

    },'json');
});

This functions work properly. 此功能正常工作。 When I click on the [x] the item of list (admin) will be hidden. 当我单击[x]时,列表项(管理员)将被隐藏。 But I need get an id of admin (where I clicked [x]). 但是我需要获得一个管理员ID(单击[x])。 Received id I have to send to php by ajax or XMLHttpRequest. 收到的ID我必须通过ajax或XMLHttpRequest发送到php。 The problem is I can't get the admin id. 问题是我无法获取管理员ID。 (I tried set the unique id - required in while loop, but I can't get it by jquery). (我尝试设置唯一ID-在while循环中需要,但jquery无法获得它)。 It's easy with php but in this case the page will be reload, I wanna miss that. 使用php很容易,但是在这种情况下,页面将被重新加载,我想念那个。

如果我正确理解了代码和问题,则可以尝试以下操作:

var admin_id = $(this).attr('delete-admin');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM