我有一个rails应用程序,我使用Disqus通用代码作为注释函数。我使用ajax远程=> true函数来显示我的帖子内容。这是我的磁盘代码
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'ginfy';
var disqus_identifier = '<%= @posts.id %>';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
我知道Disqus取决于网站URL,它需要不同的线程基于不同的URL,但在这里我使用AJAX [ URL没有变化]。检查我的动词-
<%= link_to "Read more","prayers/#{posts_item.id}",:remote => "true" %>
当我点击阅读更多然后磁盘总是打开相同的线程。我希望不同的disqus线程不同的帖子,而不牺牲我的Ajax功能。
我已经查了所有与这个问题有关的问题,但是没有一个给我答案。请帮帮我。您需要使用Disqus。当你想改变线程时重置函数。像下面这样的代码可以工作:
<script type="text/javascript">
var changeThread = function(){
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = 'new_disqus_identifier';
this.page.url = 'http://example.com/#!new_content';
this.page.title = "New Page Title";
this.language = "fr"; // only if changing the language
}
});
};
</script>
<button onclick=changeThread();>Change the Disqus thread!</button>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'ginfy';
var disqus_identifier = '<%= @posts.id %>';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>