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 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64