【问题标题】:Cannot pass bootstrap table cell data to php?无法将引导表单元格数据传递给 php?
【发布时间】:2016-07-02 12:56:22
【问题描述】:

我正在开发一个基于网络的库存系统。在我的项目中,我有一个用户管理页面,它有一个表格可以查看所有用户。

+----------------------------------------+
+ username + user type +        +        +
+----------+-----------+--------+--------+
+  sample  +  sample   +  edit  + delete +
+----------+-----------+--------+--------+
+  sample  +  sample   +  edit  + delete +
+----------+-----------+--------+--------+
+  sample  +  sample   +  edit  + delete +
+----------+-----------+--------+--------+

它有两个按钮来编辑用户类型和从数据库中删除用户。我需要从此表中获取用户名到 php 脚本,以执行删除查询。我试过了,

$(document).on('click','.remove' ,function(){
    var $item = $(this).closest("tr").find('td:eq(0)').html();
    console.log($item);
    <?php $username = <script>$item</script>?>
});

但我不能将此“用户名”变量传递给 php。这个怎么做?谢谢你:-)

【问题讨论】:

  • 使用 ajax 调用 将可变用户 nane 传递给 php

标签: php jquery html twitter-bootstrap


【解决方案1】:

要实现这一点,您需要执行这样的 ajax 请求:

$(document).on('click','.remove' ,function(){
    var $item = $(this).closest("tr").find('td:eq(0)').html();
    $.post("url/file.php", { // your php file
        username: $item
    }, function(data, status){
        // you will get response from your php page (what you echo or print)
    });
});

PHP方面:

$username = $_POST['username'];
//Do whatever you want ...
echo "success";

【讨论】:

  • 谢谢,我试试
  • 我可以将此变量发布到函数中
【解决方案2】:

您可以通过 Ajax 来完成,建议您的代码这样做:

$.ajax({
            url: "data.php",//file wich has query select to db table
            data: {id:theid},//describe your data here
            dataType: 'json',// type of data that will you get (JSON/HTML).
            type: 'POST',//sending type (POST/GET)
            success: function(data) {
               //do change the select option
            }
        });

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多