javascript - Addthis is Undefined when I use addthis, When I load page by Ajax - Stack Overflow

I'm try to show 'addthis sharing' buttons when make ajax call. at the first callby aja

I'm try to show 'addthis sharing' buttons when make ajax call. at the first call by ajax, buttons does not show, but when I reload whole page everything is OK, buttons is right place.

I searched a lots of fixes but no one works for me. one of them is addthis.toolbox(); or window.addthis but when I use word addthis insde JavaScript tag, browser debugger writes error 'addthis is undefined'.

please give me smart advice what's happen and how can I fix it ?

Code (it's a partial view which load from ajax Call):

<script type="text/javascript" src=".js#pubid=ra-xxxxx" async="async"></script>

<div class="addthis_sharing_toolbox"></div>

<script>
 addthis.toolbox(); // addthis - is undefined
</script>

I'm try to show 'addthis sharing' buttons when make ajax call. at the first call by ajax, buttons does not show, but when I reload whole page everything is OK, buttons is right place.

I searched a lots of fixes but no one works for me. one of them is addthis.toolbox(); or window.addthis but when I use word addthis insde JavaScript tag, browser debugger writes error 'addthis is undefined'.

please give me smart advice what's happen and how can I fix it ?

Code (it's a partial view which load from ajax Call):

<script type="text/javascript" src="http://s7.addthis./js/300/addthis_widget.js#pubid=ra-xxxxx" async="async"></script>

<div class="addthis_sharing_toolbox"></div>

<script>
 addthis.toolbox(); // addthis - is undefined
</script>

Share Improve this question edited May 31, 2022 at 8:45 VLAZ 29.1k9 gold badges63 silver badges84 bronze badges asked Jan 8, 2016 at 19:51 Avtandil KavrelishviliAvtandil Kavrelishvili 1,7573 gold badges28 silver badges38 bronze badges 3
  • 2 You need to show us some working sample code stackoverflow./help/mcve – dtanders Commented Jan 8, 2016 at 19:58
  • You need to show us what you are doing. A text description is not helpful when there is no code to go with it. – epascarello Commented Jan 8, 2016 at 20:13
  • I have already add code example. Thanx – Avtandil Kavrelishvili Commented Jan 8, 2016 at 20:20
Add a ment  | 

2 Answers 2

Reset to default 4

I have fixed this problem.

In my project I have 3 View level

  1. _layout
  2. View
  3. _partialview

I had addthis Js reference and button's Div inside the _partialView.

But when I move Js reference to View and change Url(add - &async=1) it works fine and now 'addthis' - is defined (till here is undefined).

Hare is full example:

View:

    <script type="text/javascript" src="http://s7.addthis./js/300/addthis_widget.js#pubid=ra-'yourPubId'&async=1"></script>
//Some Code 

_partialView:

//Some Code 
<div class="addthis_sharing_toolbox"></div>

<script>
    $(function() {
        addthis.init(); 
        addthis.layers.refresh(); 
      });
</script>

Good luck, everyone can use this perfect plugin 'addthis' when you load page by Ajax.

The async version of the addthis_widget.js script you're using was intended to be used for the newer dashboard tools, as the call to addthis.toolbox() is undefined because AddThis hasn't fully loaded yet. If you remove async="async" from the script, it should work.

Alternatively, you could add the async attribute this way:

<script src="http://s7.addthis./js/300/addthis_widget.js#pubid=ra-xxxxx&async=1" type="text/javascript">

Then before you call addthis.toolbox(), make sure you call addthis.init().

https://www.addthis./blog/2013/05/07/a-brief-history-of-using-addthis-dynamically/

-Matt

AddThis Support

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742316207a4420889.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信