【问题标题】:Not able to load bootstrap modal with ajax data无法使用 ajax 数据加载引导模式
【发布时间】:2016-06-02 11:07:37
【问题描述】:

我正在使用 codeigniter 创建我的网站。我的第一页中有一个下拉菜单,其中包含“个人资料”、“编辑”等链接。当我点击链接(个人资料)时,它应该显示带有相应用户数据的引导模式。使用 jquery 获取当前 id 和 ajax 从数据库中检索数据。但是,当我尝试使用响应数据加载引导模式时,它什么也不显示。我应该怎么做才能加载带有 ajax 响应数据的模态。?响应是一个包含用户名、地址、电话号码等的数组。

【问题讨论】:

  • 你能发布你的编码吗?
  • 希望是加载JS文件的问题。首先加载 jqery.min.js 然后加载 bootstrap.min.js。

标签: ajax twitter-bootstrap codeigniter


【解决方案1】:

模态 HTML

<div class="modal fade" id="MyModal" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
            <h4 class="modal-title">Modal Title</h4>
            </div>
            <div class="modal-body">
                <div id="UserName"></div>
                <div id="Address"></div>
                <div id="Phone"></div>
            </div>
            <div class="modal-footer" id="buttons-box">
                <button type="button" class="btn default" data-dismiss="modal">Close Modal</button>
            </div>
        </div>
    </div>
</div>

你的 jQuery 脚本

$.get('your_server_script.php', {UserId: 'UserId'}, function (response) {
    $('#UserName').text(response.UserName);
    $('#Address').text(response.Address);
    $('#Phone').text(response.Phone);

    $('#MyModal').modal('show');
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    相关资源
    最近更新 更多