954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to load JavaScript inside AJAX area?

Title should be load ajax inside ajax because facebook comments load via ajax
I am building an all AJAX site for a Facebook iFrame page and am having an issue. All the pages and what not load up dynamically just fine, but some pages use the Facebook commet system. After the AJAX has loaded the page though, the JavaScript inside does not load.
This is the Facebook comment script that I need to load inside the ajax'd content.
How would you eval that? (or whatever it is you would do?)

<script>(function(d){
  var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
  js = d.createElement('script'); js.id = id; js.async = true;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  d.getElementsByTagName('head')[0].appendChild(js);
}(document));</script>
<div class="fb-comments" data-href="<?php the_permalink(); ?>" data-num-posts="5" data-width="500"></div>

Any help greatly appreciated.

epicrevolt
Junior Poster in Training
94 posts since Oct 2010
Reputation Points: 16
Solved Threads: 6
 

Solution:
when you load up the ajax page, add this.

FB.XFBML.parse();

also place this in your header

<script src="http://connect.facebook.net/en_US/all.js#appId=YOUR_APP_ID&amp;xfbml=1"></script>
epicrevolt
Junior Poster in Training
94 posts since Oct 2010
Reputation Points: 16
Solved Threads: 6
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: