在Ajax加载后加载社交媒体脚本

时间:2013-07-10 01:14:36

标签: php ajax icons

我正在尝试将以下语法添加到现有页面,以便将社交媒体图标(linkedin,fb和twitter)添加到页面中,但总是碰撞并且它没有显示在页面上。

我是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 -

1 个答案:

答案 0 :(得分:0)

您使用的是非常旧版本的jQuery并且在较新版本中不再使用live。

其次你需要修改下面的代码,你需要触发事件附加到body而不是 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"); 
});

由于您已将事件附加到正文,因此它将从同一元素触发。

相关问题