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:
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! :)
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
If you are using the AddThis share buttons, you might have noticed that once you initialize it on page load, it does not really work for content that is loaded via ajax after the fact.
i.e. AddThis is unaware of fresly loaded content. The fix for this is pretty simple. Just ask AddThis to refresh as follows, and it will automatically regenerate the correct share links for newly loaded content
addthis.layers.refresh();
I realized that my adblocker was responsible for
not working. (addthis.layers.refresh was undefined.) This is strange since I have the exact same code on 4 sites, but only on the one it doesn't work. So if you are having problems, try turning off your adblocker to see if anything changes.
The code Alex posted worked for me when I had my adblocker turned on (uBlock origin). I decided to run it as follows, so that I do it the "right" way and only if it won't work, then run the alternative way.