weixin_33749242 2012-07-21 13:03 采纳率: 0%
浏览 25

带有jquery的AJAX上的Javascript

-

how can I handle it, to get Javascript is working after the Ajax call?

On my page (wordpress) - I have all posts on startpage. I have built in a filtersystem with which the user can filter the posts after specific stuff - like "newest, most viewed, highlighted"

I use this function beneath to make this filter work:

 <script type="text/javascript">
    $(document).ready(function(){
    $.ajaxSetup({cache:false});
    $("#new").click(function(){

        var post_id = $(this).attr("rel")
        $(".postbox_wrapper").html('<span class="filter_posts">
<img src="<?php bloginfo ('template_directory'); ?>/images/287.gif"></span>');
        $(".postbox_wrapper").load(jQuery(this).attr("href") + " .postbox_wrapper")
        return false;
    });
});

The visitior clicks on the button "new" and the posts are filtered - only the newest posts show up. But I use Javascript to have the post count of disqus, lazy image loader, etc. these JS Files are not loaded on the filtered posts. (taxonomy.php)

this here is e.g. an JS File, which would be neccessary to make lazy loader available to the filtered posts:

http://myurl/../plugins/bj-lazy-load/js/bjll.min.js?ver=0.4.0

The question is: How can I tell in the function above, to also use the JS script on the new loaded "filtered" page.

It's a bit like this: Use Ajax() function in Jquery to load PART of an external page into div

but I didn't get it to work....

thanks a lot!

  • 写回答

1条回答 默认 最新

  • weixin_33691817 2012-07-21 13:36
    关注

    I'm not sure I understand your question. Are you trying to load a script after loading a particular content in a div?

    If it is try this:

    $(function(){
        $.ajaxSetup({cache:false});
    
        $("#new").click(function(){
            var $this = $(this);
            var $PostboxWrapper = $(".postbox_wrapper");
    
            var post_id = $this.attr("rel")
    
            //I think you want load something like a loading .gif in taht point. Right?
            $PostboxWrapper.html(
                "<span class='filter_posts'>" + 
                "   <img src='<?php bloginfo ('template_directory'); ?>/images/287.gif'>" +
                "</span>"
            );
    
            $(".postbox_wrapper").load(jQuery(this).attr("href"), function()
            {
                $.getScript(
                    "http://yourUrl/../plugins/bj-lazy-load/js/bjll.min.js?ver=0.4.0",
                    function(data, textStatus, jqxhr) {
                        console.log('Load was performed.');
                    }
                );
            })
            return false;
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮