繁体   English   中英

在使用ajax,php的单击同一页面上获取ID

[英]get id on click same page using ajax, php

简介:我正在使用PHP和Ajax做一个服务器端数据表库。 当用户单击“编辑”按钮时,我想将该ID传输到PHP,以便稍后进行更新...

我基本上是将这两篇堆栈溢出文章组合在一起:

Index.php

<script type="text/javascript"> 
$(document).on('click','.edit_btn',function (){
var edit_id = $(this).attr("id");
alert(edit_id);
    $.ajax({
         url: 'index.php',
      data: { edit_id : edit_id },
        contentType: 'application/json; charset=utf-8',
        success: function(result) {
              alert(result);
        }
    });
});
</script>

编辑按钮代码:

columnDefs:
[
    {  
        targets: -1,
        render: function (data, type, row, meta) {
            return '<input type="button" class="delete_btn" id=n-"' + meta.row + '" value="delete"/> <input type="button" class="edit_btn" id=s-"' + meta.row + '" value="edit" name="edit_btn"> </a>';
        }
    }
]

我相信datatables库不建议使用URL中的get方法。 我想念什么? 谢谢。

阅读评论后,我得到了最终的解决方案:

 <script type="text/javascript"> 
    $(document).on('click','.edit_btn',function (){
          var id = $(this).attr("id").match(/\d+/)[0];
            var edit_id = $('#example').DataTable().row( id ).data();
            var edit_id = edit_id[0];
    alert(edit_id);
        $.ajax({
             url: 'index.php',
          data: { edit_id : edit_id },
            contentType: 'application/json; charset=utf-8',
            success: function(result) {
                  //alert(result);
            }
        });
    });
    </script>

谢谢所有帮助的人!

暂无
暂无

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

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