【问题标题】:Bootstrap Confirmation Does not work with ajax call引导确认不适用于 ajax 调用
【发布时间】:2016-09-27 11:34:28
【问题描述】:

可能的问题在哪里,我有一个返回 json 的服务,用这个返回来骑我的桌子。

如果我留下 statisc 记录,它会将插件作为下面的确认码运行:

<td><strong>Fatura Abril</strong><br /> Este é um aviso de que sua fatura do mÊs 04 está vencendo</td>                                      
<td class="text-right"></a> 
 <a data-toggle="confirmation" class="label label-danger" type="button" id="not-basic"><i class="fa fa-times"></i></a>
</td>

但是如果你使用函数通过json返回和组装数据,表是monstada但插件确认不起作用。

<script type="text/javascript">

$(document).ready(function(){

    var url="phptabela.php"; // PHP File
    //var url="getposts.json"; // JSON File

    $.getJSON(url,function(data){

        console.log(data);
        $.each(data.data, function(i,post){

        var newRow =
        "<tr>"

        +"<td><strong>"+post.titulo+"</strong><br />" +post.texto+"</td>"   
        +"<td class='text-right'></a> "
        +"<a data-toggle='confirmation' class='btn btn-default label label-danger' type='button' id='not-basic'> "
        +"<i class='fa fa-times'></i></a> "
        +"</td>"


        +"</tr>" ;
        $(newRow).appendTo("#json-data");
        });
    });
}); 
</script> 

我正在使用这个插件: http://bootstrap-confirmation.js.org/

【问题讨论】:

  • 在循环中使用 html ID 绝不是一个好主意,因为 ID 必须是唯一的。

标签: php jquery ajax twitter-bootstrap


【解决方案1】:

从ajax收到数据并附加到json-data后,你需要初始化新的确认

从文档中我可以看出您需要这样做:

$('[data-toggle=confirmation]').confirmation({
  rootSelector: '[data-toggle=confirmation]',
  // other options
});

【讨论】:

    猜你喜欢
    • 2017-09-22
    • 2018-03-31
    • 1970-01-01
    • 2019-01-06
    • 2011-04-04
    • 2021-08-13
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多