从弹出框内容引导 ajax 调用

Bootstrap ajax call from popover contents

本文关键字:ajax 调用      更新时间:2023-09-26

我必须从#id中的内容调用ajax或任何类型的post请求。#id是这样隐藏的:

<div id="mycontents" style="display: none;">
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-danger btn-sm" id="click_id">Click</button>
    </div>
</div>

如何从此#mycontents触发 ajax 调用?

$('#id').popover({
    trigger : 'hover',
    delay : {
        show : 1,
        hide : 10000
    },
    html : true,
    content : function() {
        return $('#mycontents').html();
    }
})

问题是某些浏览器忽略display: none元素,因此我无法从中触发任何事件。

例如,当我单击按钮时,我想触发以下内容:

$('#click_id').click(function(e) {
    $.ajax({
        type: "GET",
        url: "/click_id",
        async: true,
        dataType: "html",
        success: function(data) {
            // Do stuff
        }
    });
});

谢谢!

试试这个:

$('#id').popover({
    trigger : 'hover',
    delay : {
        show : 1,
        hide : 10000
    },
    html : true,
    content : function() {
        var myhtml = $('#mycontents').html();
        $('#mycontents', myhtml).removeAttr('style');
        return myhtml
    }
})