Disqus + ajax + died ...

I tried to load Disqus with ajax on my page, I will explain. I have one page inside, I have jqrusel, with different images, and each has its own comments.

So, when I clicked on one of these images, I made this code:

$.get("/sets/comentarios",{set_id:set_id},function(data){ $("#componet_comentarios").html(data); 

and this URL loading:

  var disqus_identifier = 'votar-<?= $id; ?>'; var disqus_url = 'www.mitrendy.com/votar/<?= $id; ?>'; // Remove the old script if it found oldDsq = document.getElementById('MitrendyComentDisqus'); if(oldDsq) { (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).removeChild(oldDsq); } (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.id = "MitrendyComentDisqus-<?= $id; ?>"; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); 

but never update comments. Later I saw on the official disqus page:

 DISQUS.reset({ reload: true, config: function () { this.page.identifier = "newidentifier"; this.page.url = "http://example.com/#!newthread"; } }); 

but this is the same when I tried to load comments using ajax, never update it.

Any idea? I'm crazy with that.

Thanks everyone!

+4
source share
1 answer

I had a similar problem, I moved my site to ajax, and the subpage previously included in php that contains disqus js now loads with ajax (a container for disqus and its scripts), but when it does not load the whole page, the scripts donโ€™t are evaluated. So I moved them to the global .js file and included a function, for example:

 var disqus_shortname = 'myname'; var disqus_identifier = 'myident'; function loadDisqus() { (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); } 

and after ajax loads the content, I call loadDisqus(); , and the board is loading. In your example, you should also pass the identifier as a parameter and define it when called, everything should work properly.

+7
source

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


All Articles