Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AddThis not working after ajax load

I have the AddThis js for bookmarking the details to the calender.This is working correctly on page load,but I do some filtering using ajax load and replace the html, after this the AddThis button not showing.here is my code for ajax .

$('document').ready(function () {

    $('.eventSelect').change(function () {
       var selectedDate = $('#eventDate').val();
        var keyword = $('#eventsearch').val();
        var url = "/EventsHome?eventDate=" + selectedDate + "&keyword=" + keyword;
       $.ajax({
           type: "GET"
          , url: url
          , success: function (data) {
              console.log($(data).find(".eventList").html());
              $(".eventList").html($(data).find(".eventList").html());
             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);

             }
          , error: function (XMLHttpRequest, textStatus, errorThrown) {

          }, comeplete: 
like image 437
Arun Avatar asked Feb 12 '14 04:02

Arun


5 Answers

Gary's answer did it for me: https://stackoverflow.com/a/21176470/3656694

Then running addthis.toolbox('.addthis_toolbox') re-initialized addthis for me.

Hope this helps someone! :)

like image 136
RestlessWeb Avatar answered Oct 17 '22 23:10

RestlessWeb


Would have added this as a comment to Sol's answer, but I lack the rep. The actual syntax for reloading the toolbox is to pass in the class selector for the toolbox, however this assumes that you have already init'ed addthis

 addthis.toolbox('.addthis_toolbox')
like image 21
srussking Avatar answered Oct 17 '22 23:10

srussking


You shouldn't need to reset the AddThis variables and reload the script, if you simply call:

addthis.toolbox();

this should re-render the buttons according to whatever configuration you have specified. Take a look at the documentation here:

http://support.addthis.com/customer/portal/articles/1293805-using-addthis-asynchronously#.UvvWw0JdWTM

like image 30
Sol Avatar answered Oct 17 '22 23:10

Sol


Use this script when you load new content:

if(typeof addthis !== 'undefined') { addthis.layers.refresh(); }

It is only solution for addthis_inline_share_toolbox!

addthis.toolbox() works only when you have specified buttons inside addthis element (mostly older versions).

like image 7
Jan Šafránek Avatar answered Oct 17 '22 23:10

Jan Šafránek


After 1 hour of trying custom codes i found this one that works perfect.

$(document).ajaxStop(function() {
  if (window.addthis) {
    window.addthis = null;
    window._adr = null;
    window._atc = null;
    window._atd = null;
    window._ate = null;
    window._atr = null;
    window._atw = null;
  }
  return $.getScript("http://s7.addthis.com/js/300/addthis_widget.js#pubid=sdive");
});

This is the source

like image 4
Alex Avatar answered Oct 17 '22 21:10

Alex