I'm having trouble reloading content of a bootstrap popover with ajax. Here's some code: http://pastie.org/3960102
The second ajax request (when I click on "a.close") returns an updated content (I can see it in the console), but it is not loaded inside the popover.
I looked around for solutions, none of them seem to work.
What else can I try? Thank you
This work form me: Inizialize popover on document ready (data is a json with HTML and size of element found)
});
On the trigger event of popover you must in sequence toggle the popover (show or hide instead), make popover-content empty and finally append data.html
Same problem, I resolve it with this trick, the code is verbose and just an exemple, optimize it !
I suppose the trick is the same to refresh title also.
If you have a better solution, plz tell me !
EDIT :
I continued investigation,
we can see on plugin code :
so, content is taken on attr "data-content", or on options given at the first call (instanciation) of popover.
But, actually, probleme is, options are cached and not refresh on every call, so wa have to use :
And bootstrap get the attr way.
Same for title :
So, doPopover function could be :
Work fine for me.
Instead of resetting the
data-content
attribute, you are able to directly access the popover tooltip content.Replace the following line:
with this working code:
Update 2012
As Pigueiras pointed out in his comment, that would destroy the default template for the popover. A better solution is to replace the contents of
.popover-content
:Update 2016
Thanks to another comment, here is the working code for Bootstrap 3:
After hours' search, I figured it out. For Bootstrap 3, you can use code below. More references are: https://github.com/twbs/bootstrap/issues/11528 and Bootstrap popover content cannot changed dynamically
if($element.data('bs.popover')) { $element.data('bs.popover').options.content = 'NEW CONTENT'; }
Why
empty()
and thenappend()
when you can just replace?EDIT:
Also, the first approach is correct and works fine (bootstrap 2.1) when popover is already initialized and you want to change the contents on the fly. You just have to call
'show'
again for the popover to refresh (content and position):