$(document).ready(function() { var limit = 6; var start = 0; var changer ="nothing"; var loadmore ="no"; filter_data(limit,start); function filter_data(limit,start) { // $('.filter_data').html('
'); var action = 'fetch_data'; var levelNAME = $('#levelname').val(); var catID = $('#catid').val(); var attr = get_filter('attr'); $.ajax({ url:"https://eramesabz.com/home/fetch_data/", method:"POST", dataType:"JSON", data:{action:action , attr:attr ,levelname :levelNAME ,catid:catID ,start:start ,limit:limit ,changer:changer ,loadmore:loadmore}, success:function(data) { console.log(changer); if (changer === "html") { $('#showproduct').html(data); }else if(changer === "append") { $('#showproduct').append(data); } } }) } function get_filter(class_name) { var filter = []; var attrID; var detailID; $('.'+class_name+':checked').each(function(){ attrID = $(this).data("attr-id"); detailID =$(this).data("detail-id"); filter.push({ 'attr':attrID, 'detail':detailID }); }); if(filter.length == 0 && loadmore =="no"){ changer = "html"; } if(filter.length == 0 && loadmore =="yes"){ changer = "append"; } if(filter.length == 1 && loadmore =="no"){ changer = "html"; } if(filter.length == 1 && loadmore =="yes"){ changer = "append"; } if(filter.length > 1 && loadmore =="no"){ changer = "html"; } if(filter.length > 1 && loadmore =="yes") { changer = "append"; } return filter; } $(document).on('click', '.loadmore', function(event){ event.preventDefault(); loadmore ="yes"; start = start + limit; filter_data(limit,start); $(".loadmore").text("دریافت اطلاعات...") setTimeout(function() { $(".loadmore").text("ادامه محصولات");; }, 1000); }); $('.common_selector').click(function(){ loadmore ="no"; limit = 6; start = 0; filter_data(limit,start); }); function submitForm() { document.getElementById("bigger-search").submit(); } $("#search_in_title").keyup(function () { $.ajax({ type: "POST", url: "https://eramesabz.com/home/searchproduct", data: { keyword: $("#search_in_title").val() }, dataType: "json", success: function (data) { if (data.length > 0) { $('#DropdownCountry').empty(); $('#search_in_title').attr("data-toggle", "dropdown"); $('#DropdownCountry').dropdown('toggle'); } $.each(data, function (key,value) { if (data.length >= 0) $('#DropdownCountry').append('