Answer the question
In order to leave comments, you need to log in
How to display slides correctly if an owl carousel ajax request is made?
<div class="carousel-wrap">
<div class="owl-carousel">
</div>
</div>
$(function() {
$('.owl-carousel').owlCarousel();
});
$.ajax('/test.php').done(function (response) {
if (typeof response === 'string' && response.length > 0) {
$('.owl-carousel').html(response);
} else {
console.log(response);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
});
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
<div class="item"><img src="http://placehold.it/150x150"></div>
Answer the question
In order to leave comments, you need to log in
$(response).filter('.item').each(function() {
$owl.trigger('add.owl.carousel', this);
});
$owl.trigger('refresh.owl.carousel');
var owl = $('.owl-carousel');
owl.owlCarousel();
$.ajax('/test.php').done(function (response) {
if (typeof response === 'string' && response.length > 0) {
$('.owl-carousel').html(response);
owl.trigger('refresh.owl.carousel');
} else {
console.log(response);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
});
$('.owl-carousel').owlCarousel();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question