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

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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败