Bootstrap Popover with External URL Data by Ajax

by WayBehind

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="container center"> <a role="button" class="btn btn-default orange new-form a" data-container="body" data-toggle="popover" data-placement="bottom" id="{{ instance.1 }}">Button A</a>

<a role="button" class="btn btn-default orange new-form b" data-container="body" data-toggle="popover" data-placement="bottom" id="{{ instance.2 }}">Button B</a>

<a role="button" class="btn btn-default orange new-form c" data-container="body" data-toggle="popover" data-placement="bottom" id="{{ instance.3 }}">Button C</a>

<a role="button" class="btn btn-default orange new-form d" data-container="body" data-toggle="popover" data-placement="bottom" id="{{ instance.4 }}">Button D</a> 
    <div id="pop-head" class="hide">Form Head</div>
     <h3>It takes few secs to load the data!</h3>

</div>

CSS

body {
    margin: 20px;
}
.center {
    width: 660px;
    margin-left:auto;
    margin-right:auto;
}

JavaScript

$('.new-form').popover({
    html: true,
    trigger: 'manual',
    title: function () {
        return $("#pop-head").html();
    },
    content: function () {
        return $.ajax({
            url: '/user/dashboard/',
            dataType: 'html',
            async: false
        }).responseText;
    }
}).click(function (e) {
    $(this).popover('toggle');
});

var a = $('.a').popover();
a.on("show.bs.popover", function (e) {
    a.data()["bs.popover"].$tip.css("max-width", "630px");
});

var b = $('.b').popover();
b.on("show.bs.popover", function (e) {
    b.data()["bs.popover"].$tip.css("max-width", "630px");
});

var c = $('.c').popover();
c.on("show.bs.popover", function (e) {
    c.data()["bs.popover"].$tip.css("max-width", "630px");
});

var d = $('.d').popover();
d.on("show.bs.popover", function (e) {
    d.data()["bs.popover"].$tip.css("max-width", "630px");
});