添加这不适用于Ajax

Gra*_*ley 13 ajax jquery addthis

我正在使用Ajax加载所有文章,但Addthis功能不正确

 $thisChild.load( permLink + ' #thePostStuff', function() {
Run Code Online (Sandbox Code Playgroud)

在所述.load()函数的回调中,我添加了此代码以引入Addthis共享功能:

var script = 'http://s7.addthis.com/js/300/addthis_widget.js?domready=1#pubid=MY-PUB-ID';
if (window.addthis){
    window.addthis = null;
}
$.getScript( script );
Run Code Online (Sandbox Code Playgroud)

加载Addthis脚本的ajax请求调用的permLink文件内容中的代码如下:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style addthis_32x32_style"
        addthis:url="<?php the_permalink(); ?>"
        addthis:title="<?php the_title(); ?>"
        addthis:description="<?php the_excerpt(); ?>"> 
    <a class="addthis_button_facebook"></a>
    <a class="addthis_button_twitter"></a>
    <a class="addthis_button_preferred_3"></a>
    <a class="addthis_button_compact"></a>
    <a class="addthis_counter addthis_bubble_style"></a>
</div>
<!-- AddThis Button END -->
Run Code Online (Sandbox Code Playgroud)

问题是,addthis没有按预期加载.它在第一次打开文章时正常工作,但在任何其他时间(除非刷新页面)它都不能包含显示文章共享次数的数字,当我检查元素时会出现这样的情况:<a class="addthis_button_expanded" target="_blank" title="View more services" href="#">1</a>

编辑:

尝试了一个已知的修复:$.getScript( script , function() { addthis.init(); });但这并没有解决问题.

编辑2012年8月14日

该网站是http://epicvan.com,我刚删除了这些数字,因为我在工作时从未想出过修复.该项目已于几个月前完成,因此我不会测试新的答案.希望如果您遇到同样的问题,他们可以帮助您!干杯

小智 33

我有同样的问题.修正了以下内容.希望能为你修复它.

原版的:

    var script = 'http://s7.addthis.com/js/300/addthis_widget.js?domready=1#pubid=MY-PUB-ID';
if (window.addthis){
    window.addthis = null;
}
$.getScript( script );
Run Code Online (Sandbox Code Playgroud)

新:

<script>
var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
if (window.addthis) {
    window.addthis = null;
    window._adr = null;
    window._atc = null;
    window._atd = null;
    window._ate = null;
    window._atr = null;
    window._atw = null;
}
$.getScript(script);
</script>
Run Code Online (Sandbox Code Playgroud)


Rya*_*Ore 5

我在这里写了一个非常详细的描述/sf/answers/1186561701/但是,要点是addthis.toolbox(".addthis_toolbox"); 正确的解决方案, 重要的是要注意每次加载新的ajax内容时都应该调用它.

HTML

 <div class="addthis_toolbox addthis_default_style ">
    <a class="addthis_button_facebook" style="cursor:pointer"></a> 
    <a class="addthis_button_twitter" style="cursor:pointer"></a> 
    <a class="addthis_button_email" style="cursor:pointer"></a>
 </div>
Run Code Online (Sandbox Code Playgroud)

JavaScript的

// onload of the ajax content
addthis.toolbox('.addthis_toolbox'); 
Run Code Online (Sandbox Code Playgroud)

另请注意,任何以iframe形式加载的内容(如facebook),如果它嵌套在'.addthis_toolbox'容器中,都会导致问题.我建议将它放在它自己的容器中,并在它们上面调用toolbox()方法.

有关详细信息,请参阅我的链接