我试图在网站上通过ajax来使用Diqus评论系统加载文章和评论,但我无法使其正常工作。
我使用jQuery,并使用“ .load”操作加载整篇文章(包括注释)。此外,我还使用他们在其站点中提供的代码:http://docs.disqus.com/help/85/ 。
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = "newidentifier";
this.page.url = "http://example.com/#!newthread";
}
});
我真的不知道我在做什么......我的代码是这样的:
$(".cargaAqui").load("http://"+ document.domain + "/myArticle"+id, function() {
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = "myArticle" + id;
this.page.url = 'http://' + document.domain +'/view-'+ id+'#!newthread';
}
});
有什么想法吗?谢谢!
I've made a basic template with working DISQUS 2012 comments loading with ajax via jquery-pjax.
DISQUS 2012 does not work with DISQUS.reset yet, but they're working on it.
If you need DISQUS.reset to reload comments after ajax loading content, you'll need to turn off 2012 features in DISQUS admin.
[UPDATE:] DISQUS.reset has since been implemented in DISQUS 2012, so the workaround above is not really necessary. However, push state combined with DISQUS.reset work really well together.
I agree with Adam. Disqus script tags accumulate. I did that :
var head = document.getElementsByTagName('head')[0];
head.removeChild(head.lastElementChild);
Put it just before the DISQUS function.
It works perfectly for me, because Disqus script tag is at the end of head. I run firebug again in Chrome, and Disqus script tags didn't accumulate any more.