【问题标题】:Modal receiving wrong data模态接收错误数据
【发布时间】:2019-09-26 20:15:23
【问题描述】:

我有一个包含数据库信息的列表,每条记录旁边都有一个用于编辑记录数据的按钮。问题是当我尝试发送我要编辑的注册表的 id 时,我总是收到相同的输出,简单的单词:Array。

这是桌子:

<th><?php echo $row_usuario["id_employee"]; ?></th>
<td><?php echo $row_usuario["nome"]; ?></td>
<td><?php echo $row_usuario["email"]; ?></td>
<td>
    <a href="#Edit" id="custId" data-toggle="modal" data-id=" '.$row_usuario['id_employee'].'">
        <i class="material-icons" style="color:#2A6F46">edit</i>
    </a>
</td>

ajax:

$(document).ready(function(){
    $('#Edit').on('show.bs.modal', function (e) {
        var rowid = $(e.relatedTarget).data('id');
        $.ajax({
            type : 'post',
            url : 'list_emp.php',
            data :  'rowid='+ rowid,
            success : function(data){
            $('.fetched-data').html(data);//Show fetched data from database
            }
        });
     });
});

查询部分:

//database connection include before this
if($_POST['rowid']) {
    $id = $_POST['rowid'];
    //here is the problem, i'm not receiving the real id, just the word "Array" and i can't run the query because this
}

模态:

<div class="fetched-data">Here i want to show the form with the info to be edit</div>

谁能帮我找出错误?

【问题讨论】:

    标签: javascript php jquery mysql ajax


    【解决方案1】:

    每条记录旁边都有一个编辑记录数据的按钮

    所以我认为您的编辑按钮上需要 class 而不是 id 所以把你的html改成这样:

    <th><?php echo $row_usuario["id_employee"]; ?></th>
    <td><?php echo $row_usuario["nome"]; ?></td>
    <td><?php echo $row_usuario["email"]; ?></td>
    <td>
        <a href="#Edit" class="fancyEditButton" data-toggle="modal" data-id=" '.$row_usuario['id_employee'].'">
            <i class="material-icons" style="color:#2A6F46">edit</i>
        </a>
    </td>
    

    在你的 ajax 上:

    $(document).ready(function(){
        $('.fancyEditButton').on('click', function (e) {
            e.preventDefault();
            var rowid = $(this).data('id');
            $.ajax({
                type : 'post',
                url : 'list_emp.php',
                data :  'rowid='+ rowid,
                success : function(data){
                    $('.fetched-data').html(data);//Show fetched data from database
                }
            });
        });
    });
    

    【讨论】:

      【解决方案2】:

      试试这个

       $.ajax({
              type : 'post',
              url : 'list_emp.php',
              data :  {rowid: rowid}
              success : function(data){
              $('.fetched-data').html(data);//Show fetched data from database
              }
          });
      

      就像这里显示的post ajax data to PHP and return data

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-06
        • 1970-01-01
        • 1970-01-01
        • 2018-07-13
        • 2013-03-08
        • 1970-01-01
        • 2017-02-01
        • 2020-11-21
        相关资源
        最近更新 更多