weixin_33692284 2014-04-18 22:55 采纳率: 0%
浏览 26

Ajax加载后重新运行脚本

I'm trying to load a content into a div with this:

 $(document).ready(function(){


    $(".produkty").click(function(){
        var post_id = $(this).attr("href");    
        $("#single_product_box").load(post_id + " #main" );
        return false;
     });
});

The other scripts I use are here:

  <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/js/jcarousellite_1.0.1.min.js" type="text/javascript"></script>
   <script>


   $(function() {
       $(".anyClass").jCarouselLite({
         btnNext: ".next-any",
         btnPrev: ".prev-any"
       });
   });
   $(function() {
       $(".anyClass-2").jCarouselLite({
         btnNext: ".next-any2",
         btnPrev: ".prev-any2"

       });
   });

Everything is fine, but after first load it stopped working. I've tried to use something like this:

 $.ajax({
    url: '$post_id',
    cache: false,
    beforeSend: function (data) {
        $('#single_product_box').html("Loading...");
    },
    success: function (data) {
        if (data!='error'){
            $('#single_product_box').html(data);
        }else{
            $('#single_product_box').html("<span style='color:red;'>Error!</span>");
        }
    },
    error: function (data) {
        $('#single_product_box').html("<span class='error'>Error!</span>");
    }
});

but I cannot make it work again, I even tried to put the scripts into loaded content, but it disappears as well. I just had no more ideas.

  • 写回答

2条回答 默认 最新

  • weixin_33724059 2014-04-19 00:17
    关注

    As I said in the comments, it looks like jQuery is being loaded multiple times (which is another issue - you need to look into cleaning up your mark up). All of the plugins that register prior are lost (because they use the loaded $.fn, which is overwritten when a later jQuery is loaded...)

    I see the following your HTML

    Line 32
    <script type='text/javascript' src='http://usb-solutions.pl/wp-includes/js/jquery/jquery.js?ver=1.11.0'></script>    
    
    Line 40
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    
    Line 323
    <script type="text/javascript"> 
        $.getScript("http://usb-solutions.pl/wp-content/themes/usb-solutions/js/jcarousellite_1.0.1.min.js");
        $.getScript("//code.jquery.com/jquery-1.11.0.min.js");
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 数电几道习题,写出作答过程,ai一律不采用
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52