当使用ajax、jquery动态追加owl旋转木马项时,该项不起作用

当使用ajax、jquery动态追加owl旋转木马项时,该项不起作用,jquery,html,owl-carousel,Jquery,Html,Owl Carousel,当使用ajax、jquery动态追加owl旋转木马项时,该项不起作用 下面是我的ajax代码。任何帮助都将不胜感激 提前谢谢 $.ajax({ type: "POST", url: "urllinks", data: 'id='+id, dataType: 'json', cache: false, su

当使用ajax、jquery动态追加owl旋转木马项时,该项不起作用 下面是我的ajax代码。任何帮助都将不胜感激

提前谢谢

 $.ajax({
                type: "POST",
                url: "urllinks",
                data: 'id='+id,
                dataType: 'json',
                cache: false,
                success: function(data) {
                var locationoffers='';
                locationoffers+='<div id="owl-demo" class="owl-carousel">';
                $.each(data, function(i, item) {
                    locationoffers+='<div class="item"><a href="#" class="thumbnail"><img src="<?php echo base_url(); ?>assets/uploads/location_offers/'+data[i].image+'"  alt="Location Logo" /></a><span class="tocenter"> <h3>'+data[i].tittle+'</h3></span></div><div class="desc"><span> <p>'+data[i].message+'</p> </span></div><br><div class="tocenter"><a href="http://www.google.com" target="_blank" class="btn green">Grabit</a></div> </div>';
                });

            locationoffers+='</div>';

               $('#display_adds').html(locationoffers);
              $('.owl-carousel').owlCarousel();


        }


   });

     }   
$.ajax({
类型:“POST”,
url:“url链接”,
数据:“id=”+id,
数据类型:“json”,
cache:false,
成功:功能(数据){
var locationoffers='';
locationoffers+='';
$。每个(数据、功能(i、项){
locationoffers+=''+数据[i]。标题+''+数据[i]。消息+'


'; }); locationoffers+=''; $('#display_adds').html(locationoffers); $('.owl carousel').owlCarousel(); } }); }

在ajax调用后显示owl转盘时,您需要在收到响应后对其进行初始化,因此请尝试将转盘放入函数中

  function init_carousel() {
     $('.owl-carousel').owlCarousel();
  }; 
并在ajax响应成功刷新旋转木马时调用该函数。同时,为了在页面加载JU时进行初始化,请在中调用函数:

jQuery(document).ready(function() {
   init_carousel();
});

除上述答案外,请尝试使用owlCarousel属性控制行为,如下所示:

$('.searchPageGallery').owlCarousel({
        margin:0,
        nav:true,
        loop:true,
        stagePadding:0,
        center:true,
        dots:false,
        lazyLoad:true,
        items:1,
        responsiveClass:true,
        responsive:{
            0:{
                items:1,
                nav:true,
                dots:false
            },
            1025:{
                items:1,
                nav:true,
                dots:false
            },
            1200:{
                items:1,
                nav:true,
                nav:true
            }
        }
    });

您好..谢谢您的回复..我已经尝试过这种方式..当我尝试附加时,只有一个项目(图像)…正在添加到旋转木马中,其余项目缺少对齐..我已附加..屏幕截图也..您检查参考,,,我也面临同样的问题。所有图像都一个接一个地堆叠起来。可能滑块无法正确初始化。