Uncaught ReferenceError: addthis is not defined while clicking on the share button

264 Views Asked by At

I am using addthis on my HTML website. What I am doing is, I am displaying all the rows on the page, and each row has a separate share button. When the user clicks on the share button then I have to show all the social icons.

I tried the below code but I am getting an error in the console after clicking on the share button.

Uncaught ReferenceError: addthis is not defined

Script.js

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

    $(document).on('click', '.companyShareWrap > a', function(e){
    e.preventDefault();
    var company_id=$(this).data("id"); 
    $.ajax({
        url: 'process.php',
        method:'post',
        dataType: "json", 
        data:{company_id:company_id,action:"sharePages"},  
        success: function(data){
        $('.sharebuttonAjax').html(''); //clear previous social and metatags

        $(".sharebuttonAjax"+company_id).append(data['socialbuttons']); 
         addthis.init(); 
         addthis.layers.refresh(); 
    
        }
    });
    });

PHP

if($_REQUEST['action']=='sharePages'){
$c_id=$_POST['company_id'];
$sql = "SELECT `company_img`, `company_name`, `company_desc` FROM `tbl_companyList` WHERE  company_id=:company_id";
$stmt= $pdo->prepare($sql);
$stmt->bindParam('company_id', $c_id);
$stmt->execute();
$result = $stmt->fetch();


$getsharebuttons='<style>.sharebuttonAjax{position: absolute;bottom: 35px;
left: -48px;}.at-label{display:none}.at-resp-share-element{width:170px;}.at-share-btn-elements{display:flex;}.at-style-responsive .at-share-btn{padding:0 !important}</style><div class="addthis_inline_share_toolbox" data-url="https://www.test.com/demo/index.php" data-title="'.$result['company_name'].'" data-description="'.$result['company_desc'].'" data-media="'.$result['company_img'].'" style="clear: both;">
            <div id="atstbx" class="at-resp-share-element at-style-responsive addthis-smartlayers addthis-animated at4-show" aria-labelledby="at-73d0007c-6879-44b0-b2ea-3f01c82d7f53" role="region">
                <div class="at-share-btn-elements"></div>
            </div>
        </div>';


$metatags="";
$getResult=array('metatags' =>$metatags,'socialbuttons'=>$getsharebuttons);                 

// print_r($getResult);
// die();
echo json_encode($getResult);


}

I am getting the response but social icons are not displaying. What can I try next?

0

There are 0 best solutions below