Facebook "Like a box" on the loaded ajax page only loads for the first time?

I want to show the Facebook Like Like plugin and other FB code on the loaded ajax page.

When I upload it to a regular html page, it works as it should, but when I try to put it on the ajax download page , it only downloads the first time , when I click on the link to download the page a second time, when the page does not load ? This is only a page load if I clear the cache.

The index file initializes the fb code.

FB.init({ appId : '277065222', // App ID status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true, // parse XFBML oauth : true }); 

I load ajax page with this code:

  function loadFacebook(){ $('#container').load('http://www.manmade.se/manmade/guiden/facebook_onweb.html'); FB.XFBML.parse(); } 

And on the loaded ajax page, I have a facebook code, like facebook like field.

+6
source share
3 answers

you can call fb par script in your page load after calling fb script

 (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=11111code"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); $(document).ajaxComplete(function () { try { FB.XFBML.parse(); } catch (ex) { } }); 
+14
source

reloadlike.html

 <div class="fb-like fltLeft" data-href="http://yrl_like" data-send="false" data-layout="button_count" data-width="87" data-show-faces="false"></div> 

this should work every time.

I think your callback is wrong.

 $('#container').load('reloadlike.html', function() { FB.XFBML.parse(); }); 
+4
source

By changing a bit of the sample code from bugrasitemkar, at the end of the ajax code, I include this jquery script and it works:

 <script type="text/javascript"> $(document).ready(function() { try { FB.XFBML.parse(); } catch (ex) { } }); </script> 
0
source

Source: https://habr.com/ru/post/912577/


All Articles