Ajax hiển thị bài viết kết hợp owl carousel

Ads By Google

Hướng dẫn viết Ajax hiển thị bài viết kết hợp owl carousel, các bạn có thể tham khảo thêm để áp dụng trong quá trình viết code

Code Ajax như sau

<script type=’text/javascript’>
//<![CDATA[
var label_product = “san-pham”,
number = 12;
$.ajax({
url: ‘/feeds/posts/default/-/’ + label_product,
type: ‘GET’,
data: {
‘max-results’: number,
‘alt’: ‘json’
},
dataType: “jsonp”,
success: function(e) {
for (var n = 0; n < e.feed.entry.length; n++) {
for (var t = 0; t < e.feed.entry[n].link.length; t++)
if (“alternate” == e.feed.entry[n].link[t].rel) {
var post_link = e.feed.entry[n].link[t].href;
break
}
if (“content” in e.feed.entry[n]) var r = e.feed.entry[n].content.$t;
else if (“summary” in e.feed.entry[n]) r = e.feed.entry[n].summary.$t;
else r = “”;
r = r.replace(/<S[^>]*>/g, “”);
var post_thumb = e.feed.entry[n].media$thumbnail.url.replace(“s72-c”, “s1600”),
post_title = e.feed.entry[n].title.$t,
giaban = -1 != r.indexOf(“[giaban]”) ? r.substring(r.indexOf(“[giaban]”) + 8, r.indexOf(“[/giaban]”)) : “Liên hệ”,
giacu = -1 != r.indexOf(“[giacu]”) ? r.substring(r.indexOf(“[giacu]”) + 8, r.indexOf(“[/giacu]”)) : “”;
price1 = giacu.replace(/,/gi, “”);
price2 = giaban.replace(/,/gi, “”);
if (-1 != r.indexOf(“[giacu]”)) {
var qq = parseInt(price2) – parseInt(price1),
ww = qq / parseInt(price2),
ee = ww * 100,
rr = ee.toFixed(0) + “%”,
post_sale = ‘<div class=”saleright”>’ + rr + ‘</div>’;
} else {
post_sale = “”;
}

var content = ‘<div class=”item_product_main simpleCart_shelfItem”> <div class=”product-loop-1 product-loop-2 product-base”> <div class=”product-thumbnail”> ‘ + post_sale + ‘ <a class=”image_link display_flex” href=”‘ + post_link + ‘” title=”‘ + post_title + ‘”> <img src=”‘ + post_thumb + ‘” alt=”‘ + post_title + ‘” class=”item_thumb”> </a> <div class=”product-action clearfix hidden-xs”> <div class=”variants form-nut-grid”> <div class=”group_action”> <a title=”Xem nhanh” href=”‘ + post_link + ‘” class=”xem_nhanh btn-circle btn_view btn right-to quick-view hidden-xs hidden-sm hidden-md”> Xem nhanh </a> <button class=”btn-buy btn-cart btn btn-circle left-to add_to_cart item_add” title=”Đặt hàng ngay”><i class=”fas fa-shopping-basket iconcart”></i></button> </div> </div> </div> </div> <div class=”product-info a-center”> <h3 class=”product-name”><a href=”‘ + post_link + ‘” title=”‘ + post_title + ‘” class = “item_name”>’ + post_title + ‘</a></h3> <div class=”product-hideoff”> <div class=”product-hide”> <div class=”price-box clearfix”> <div class=”special-price”> <span class=”price product-price item_price”>’ + giaban + ‘</span> </div> <div class=”old-price”> <span class=”price product-price-old”> ‘ + giacu + ‘ </span> </div> </div> </div> </div> </div> </div> </div>’;

$(‘#sanphammoi’).owlCarousel().trigger(‘add.owl.carousel’, [jQuery(‘<div class=”owl-item”>’ + content + ‘</div>’)]).trigger(‘refresh.owl.carousel’);

}
}
});
//]]>
</script>

Ads By Google

ads nè