0

I'm trying to add a popover via an ajax call with rails. I see in firebug that the content loads fine, but the popover isn't loading.

All other popovers work on the page, and if I reload the page, the popover works too...but it just doesn't work on the ajax call. What am I missing?

update.js

$("#new-pins").append("<div class='pinimage' data-original-title=''><img src='/images/<%= @changes[0] %>.png' class='pinimage' data-content='hello' data-original-title=''></a></div>")

show.html popover javascript:

<script>
$(function () {
    $('.pinimage').popover({ html : true });
});
</script>

Here's what loads after the ajax call:

<div class="pinimage" data-original-title="">
   <img class="pinimage" data-original-title="" data-content="hello" src="/images/card.png">
</div>

Thank you for any help!

Pigueiras
  • 18,778
  • 10
  • 64
  • 87
user749798
  • 5,210
  • 10
  • 51
  • 85
  • If you put a `console.log("Testing")` inside the second function, does the console show something? Does the `.pinimage` exist before you establish the event? And also, if you put `jquery` in the tags in this type of questions, probably somebody that knows more than me will answer faster hehe. – Pigueiras Jul 21 '12 at 11:52
  • It might help to post your controller code, and your form code too. My first guess is that the edit form might need a :remote => true passed to it. – Josh W Lewis Jul 21 '12 at 12:40
  • will post the controller code, but the controller seems to be acting fine (it has remote => true in it), and all of the right html loads, but for some reason the popover won't work. – user749798 Jul 21 '12 at 14:36
  • @pigueiras...i tried loading the div with ajax and have it preexisting in the view before, but didn't make a difference. Do I somehow have to call the popover javascript function again after the ajax call? – user749798 Jul 21 '12 at 14:41
  • looks like I had to pre-load an empty .pinimage and then replace the empty content. popovers must somehow be pre-loaded – user749798 Jul 21 '12 at 17:37
  • I have a similar situation. I use jQuery get to load in some content that includes popovers - they won't fire when loaded in dynamically for some reason. Still trying to get to the bottom of it. – Craig Hooghiem Jul 24 '12 at 20:51

1 Answers1

1

I had a similiar issue and finally got it to work when I realized that I was calling the jquery on document load but I had to call it again in the .js.erb file.

Community
  • 1
  • 1
purplerice
  • 473
  • 1
  • 6
  • 22