2013-07-10 54 views
0

我試圖將以下語法添加到現有頁面,以便將社交媒體圖標(linkedin,fb和twitter)添加到頁面中,但始終碰到並且它沒有顯示在頁。在Ajax加載後加載社交媒體腳本

我是新來的,尤其是ajax,我不知道我的錯誤在哪裏,我只是想在新聞結尾加載圖標。

這裏是我的代碼

<!--SEA New Add--> 
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script> 
<script> 
$(document).ready(function(){ 
    $("body").live("runScripts", function(){ 
     $(init);  

     function init() { 
      $.get('news-sharesocial.html', inject); 
     } 

     function inject(data) { 
      debugger; 
      $('.news_sharesocial').html(data); 
      //$('body').html(data); 
      //document.write(data); 
     } 
    }); 

    $('.news_sharesocial').trigger("runScripts"); 
    //$("body").trigger("runScripts"); 

}); 
</script> 

注:

  • 我把代碼放在網頁的結束,因爲這是唯一的新聞,這是一個模板。

欣賞這方面的任何幫助,我一直在爲此奮鬥了一段時間。 非常感謝您

-sea-

回答

0

第一件事情你使用很老版本的jQuery,住在較新的版本已經過時標籤。

其次你需要修改的代碼如下,你需要觸發事件附加到身體不 news_sharesocial

$(document).ready(function(){ 
$("body").live("runScripts", function(){ 
    $(init);  

    function init() { 
     $.get('news-sharesocial.html', inject); 
    } 

    function inject(data) { 
     debugger; 
     $('.news_sharesocial').html(data); 
     //$('body').html(data); 
     //document.write(data); 
    } 
}); 
$("body").trigger("runScripts"); 
}); 

正如你所連接的情況下,以身體所以它會從相同的元素被觸發。