Load a Bootstrap popover content with AJAX. Is this possible?

jquery bootstrap popover dynamic content
bootstrap popover change content dynamically
bootstrap popover position issue
jquery ajax tooltip dynamic content
bootstrap tooltip on ajax loaded content
bootstrap tooltip on click
bootstrap popover dynamic content jsfiddle
load dynamic content in bootstrap popover

The appropriate bits of what I tried are here:

<a href="#" data-content="<div id='my_popover'></div>"> Click here </a>

$(".button").popover({html: true})

$(".button").click(function(){
    $(this).popover('show');
    $("#my_popover").load('my_stuff')
})

When I click, I see the request get made, but doesn't populate the popover. I don't even see HTML for the popover get added to the DOM, but that could be firebug.

Has anyone tried this?

See my blog post for the working solution: https://medium.com/cagataygurturk/load-a-bootstrap-popover-content-with-ajax-8a95cd34f6a4

First we should add a data-poload attribute to the elements you would like to add a pop over to. The content of this attribute should be the url to be loaded (absolute or relative):

<a href="#" title="blabla" data-poload="/test.php">blabla</a>

And in JavaScript, preferably in a $(document).ready();

$('*[data-poload]').hover(function() {
    var e=$(this);
    e.off('hover');
    $.get(e.data('poload'),function(d) {
        e.popover({content: d}).popover('show');
    });
});

off('hover') prevents loading data more than once and popover() binds a new hover event. If you want the data to be refreshed at every hover event, you should remove the off.

Please see the working JSFiddle of the example.

Load a Bootstrap popover content with AJAX, Load a Bootstrap popover content with AJAX. Loading a content via AJAX in a Bootstrap popover is a very common pattern and, although it is not supported out of the box by Bootstrap, it is very easy to get this functionality with jQuery. And in JavaScript, preferably in a $(document). ready(); When ajax loading lasts too much (or mouse events are too quick) we have a.popover (‘show’) and no.popover (‘hide’) on a given element causing the popover to remain open. I preferred this massive-pre-load solution, all popover-contents are loaded and events are handled by bootstrap like in normal (static) popovers.

Works ok for me:

$('a.popup-ajax').popover({
    "html": true,
    "content": function(){
        var div_id =  "tmp-id-" + $.now();
        return details_in_popup($(this).attr('href'), div_id);
    }
});

function details_in_popup(link, div_id){
    $.ajax({
        url: link,
        success: function(response){
            $('#'+div_id).html(response);
        }
    });
    return '<div id="'+ div_id +'">Loading...</div>';
}

PHP AJAX Jquery, In this tutorial we are going to discuss how to fetch data from mysql table and load that data into Bootstrap popover plugin by using PHP with� Feb 16, 2017 · 1 min read Loading a content via AJAX in a Bootstrap popover is a very common pattern and, although it is not supported out of the box by Bootstrap, it is very easy to get this

Having read all these solutions, I think the solution becomes much simpler if you use a synchronous ajax call. You can then use something like:

  $('#signin').popover({
    html: true,
    trigger: 'manual',
    content: function() {
      return $.ajax({url: '/path/to/content',
                     dataType: 'html',
                     async: false}).responseText;
    }
  }).click(function(e) {
    $(this).popover('toggle');
  });

Popovers � Bootstrap, Within the tooltip, you can show content dynamically using jQuery AJAX. For this require Duration: 10:33 Posted: Jun 18, 2020 Load Dynamic Content in Bootstrap Popover with Ajax, PHP & MySQL Last Updated: 25 July, 2017 25 July, 2017 PHPZAG Team PHP A Popover is similar to tool-tips as it hovers over its parent window but contain much more content.

Dynamically load content on Bootstrap Tooltip with AJAX, Learn XML Learn XML AJAX Learn XML DOM Learn XML DTD Learn XML For a tutorial about Popovers, read our Bootstrap Popover Tutorial. The data- content attribute specifies the text that should be displayed inside the popover's body. the popover will display on the left side when possible, otherwise on the right. This way we can load dynamic mysql table content into Bootstrap popover by using php script with Jquery and Ajax. Here we have fetch mysql table data by using php script and we have execute php script by using ajax method and in jquery function we have used ajax method and by Bootstrap popover method we have called jquery function and so this way we can load dynamic html data into Bootstrap popover.

A variation of the code from Çağatay Gürtürk, you could use the delegate function instead and force hiding the popover on hoverout.

$('body').delegate('.withajaxpopover','hover',function(event){
    if (event.type === 'mouseenter') {
        var el=$(this);
        $.get(el.attr('data-load'),function(d){
            el.unbind('hover').popover({content: d}).popover('show');
        });
    }  else {
        $(this).popover('hide');
    }
});

Bootstrap JS Popover Reference, Learn XML Learn XML AJAX Learn XML DOM Learn XML DTD Learn XML Schema The difference is that the popover can contain much more content. Tip: Plugins can be included individually (using Bootstrap's individual "popover.js " file), the popover will display on the left side when possible, otherwise on the right. Use Bootstrap Popover to load external content through Ajax It seemed easy to load an external contents through Ajax onto Bootstrap Popover at first. In fact, it wasn't as straightforward as I would like. Using the content () function, it is straightforward to load any static content.

Bootstrap Popover, Load a Bootstrap popover content with AJAX. Twitter Bootstrap Popover with dynamically Duration: 15:49 Posted: Nov 18, 2016 When the code is pasted inside of the original HTML, Bootstrap Popver and Tooltip work because HTML code is present when the document finishes loading. When it’s the response from an AJAX call, it won’t run inside of $(), because the “document ready” event already fired some time ago. So the correct way to call Popover or Tooltip when content are loaded dynamically with AJAX is:

Twitter Bootstrap popover tutorial, Twitter Bootstrap Popover is created using a custom Jquery Plugin. Make sure that you load bootstrap-tooltip.js before bootstrap-popover.js. <a href="#" id=" example" class="btn btn-danger" rel="popover" data-content="It's for popover</ a> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs� This is my code, but it will not work. When I use the native Bootstrap PopOver with HTML in it's content, the frontend is not displaying that PopOver and the HTML Source is malformatted. &lt;!

Bootstrap popover - Ajax + Hover, Bootstrap popover, content loaded from ajax, triggered by hover, without closing when user mouses over popover content When ajax loading lasts too much (or mouse events are too quick) we have a .popover('show') and no .popover('hide') on a given element causing the popover to remain open. I preferred this massive-pre-load solution, all popover-contents are loaded and events are handled by bootstrap like in normal (static) popovers.

Comments
  • I haven't worked with bootstrap, but I would imagine that it's possible the element doesn't exist when you're trying to add content to it, but that's a guess. Are you getting any javascript errors?
  • If you have multiple popovers and want to load different content for each popover, then this answer is very neat and allows you to retain a lot of the out of the box setup for popovers - all you need to do is store the ID of the popover on attributes of the link, and read them in the 'shown.bs.popover' handler: stackoverflow.com/a/39028723/1371408
  • I got some weirdness when I moused over twice before the ajax call completed... My popvers would "stick" open. I solved it by moving the "el.unbind('hover')" to right before the $.get().
  • This workes, but the popover also stick for me, even though the unbind is before the get
  • If you're trying to load an external URL, you'll run into cross-domain access restrictions. To get around this, you can set the popover's html property to true, then set the content property to an iframe HTML tag, like content: '<iframe src="http://www.google.com"></iframe>'. You'll also need to override the max-width property of your popover using CSS, and most likely remove the styling of the iframe using CSS as well.
  • @FrzKhan you can use the e.off('hover') method
  • this doesn't work due to stackoverflow.com/questions/4111194/… changing to .hover(function(){}) works.
  • Genius answer! and thats why edited it to make it more readable
  • Great solution. With the current version of bootstrap however it seems that der might be some issue to this method github.com/twbs/bootstrap/issues/12563 .I had the twice issue and the fast solution was to ensure a title in each popover. This also means that I actually never see the Loading text you are using.
  • Works, except i had to use data-link instead of href, when using href my browser would simply opens url in href in new window.
  • Does this not cause alignment issues? When using this approach on 3.3.1 (and using Chrome), the popover aligns itself when "Loading..." is displayed, but as soon as the true content of my popover is loaded, the alignment doesn't adjust accordingly...