You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

点击按钮无法弹出Modal展示记录集问题求助

问题修复:点击按钮无法弹出Bootstrap Modal展示反馈记录

问题根源分析

  1. 事件参数未定义:点击事件回调函数未传入event参数,导致e.preventDefault()抛出错误,直接中断后续Modal弹出逻辑。
  2. AJAX返回内容冗余:show_gess_responses.php返回了完整的HTML文档结构(包含<html>、<head>等标签),插入到Modal的div中会造成DOM结构混乱,同时重复引入jQuery、Bootstrap等依赖可能引发冲突。
  3. 主页面依赖缺失(潜在问题):若主页面未引入jQuery和Bootstrap的JS/CSS,Modal功能本身无法正常工作。

修复步骤

1. 修正主页面的点击事件脚本

给点击回调函数添加e参数,确保e.preventDefault()能正常执行,同时新增错误处理方便排查问题:

<script>
$(document).ready(function() {
    $('.view_data').click(function(e){  // 添加e参数
        var url = "show_gess_responses.php";
        $.ajax({
            url: url,
            method: 'GET',
            data: {
                feedbackID2: $(this).attr("id"),
            },
            success: function(result){
                $('#response_details').html(result);       
                $('#dataModal').modal('show');
            },
            error: function(xhr, status, error) {
                console.error('AJAX请求失败:', error);
            }
        });
        e.preventDefault();
    });
});
</script>

2. 简化show_gess_responses.php返回内容

移除完整的HTML文档结构,只保留表格、DataTables初始化脚本和必要样式,避免与主页面的依赖冲突,同时修复颜色值错误:

<?php
$gess_feedback_responses = new WA_MySQLi_RS("gess_feedback_responses",$sdpc_i,0);
$gess_feedback_responses->setQuery("SELECT * from gess_feedback_response where feedbackID = ?");
$gess_feedback_responses->bindParam("i", $_GET['feedbackID2'], "-1"); // 简化参数绑定,去掉多余字符串拼接
$gess_feedback_responses->execute();
?>

<style type="text/css">
td img {margin: 0;}
table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after { 
    content: " \25B4\25BE" 
}
table.sortable tbody tr:nth-child(2n) td {
  background: #cccccc;
}
table.sortable tbody tr:nth-child(2n+1) td {
  background: #ccffff; /* 修复原代码颜色值错误:#ccfffff改为#ccffff */
}
</style>

<table id="example" class="table table-responsive table-striped table-bordered" width="100%" border="0" cellspacing="0">
    <thead>
        <tr>
            <th align="left" valign="top"><strong><font size="-1">Date Submitted</font></strong></th>
            <th align="left" valign="top"><strong><font size="-1">Date Submitted</font></strong></th>
            <th align="left" valign="top"><strong><font size="-1">Name</font></strong></th>
            <th align="left" valign="top"><strong><font size="-1">Response</font></strong></th>
        </tr>
    </thead>
    <tbody>
        <?php
        $wa_startindex = 0;
        while(!$gess_feedback_responses->atEnd()) {
            $wa_startindex = $gess_feedback_responses->Index;
        ?>
        <tr>
            <td><?php echo($gess_feedback_responses->getColumnVal("date_submitted")); ?></td>
            <td><?php echo date("m/d/Y", strtotime($gess_feedback_responses->getColumnVal("date_submitted"))); ?></td>
            <td></td>
            <td><?php echo($gess_feedback_responses->getColumnVal("response")); ?></td>
        </tr>
        <?php
            $gess_feedback_responses->moveNext();
        }
        $gess_feedback_responses->moveFirst();
        unset($wa_startindex);
        unset($wa_repeatcount);
        ?>
    </tbody>
</table>

<script type="text/javascript">
$(document).ready(function() {
    var table = $('#example').DataTable( {
        "columnDefs": [
            {
                "targets": [ 0 ],
                "visible": false,
                "searchable": false
            }
        ],
        "order": [[ 0, "desc" ]],
    } );
});
</script>

3. 确保主页面引入必要依赖

在主页面的<head>中添加完整的依赖(若尚未引入,注意使用完整版jQuery而非slim版,避免AJAX功能缺失):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jq-3.3.1/jszip-2.5.0/dt-1.10.24/b-1.7.0/b-colvis-1.7.0/b-html5-1.7.0/b-print-1.7.0/r-2.2.7/sc-2.0.3/sb-1.0.1/datatables.min.css"/> 
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/jq-3.3.1/jszip-2.5.0/dt-1.10.24/b-1.7.0/b-colvis-1.7.0/b-html5-1.7.0/b-print-1.7.0/r-2.2.7/sc-2.0.3/sb-1.0.1/datatables.min.js"></script>

内容的提问来源于stack exchange,提问作者lwaters

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 06:05:02