$('.load-more-blogs').click(function () { var row = Number($('#row').val()); var allcount = Number($('#all').val()); var id_categoria = Number($('#id_categoria').val()); var rowperpage = Number($('#quante').val()); var lang = $('#session_lang').val(); row = row + rowperpage; if (row <= allcount) { $("#row").val(row); $.ajax({ url: 'https://www.dbtfibre.com/assets/ajax/getBlogs.php', type: 'post', data: {row: row, rowperpage: rowperpage, id_categoria: id_categoria}, beforeSend: function () { $(".load-more-blogs a").text('Loading'); }, success: function (response) { setTimeout(function () { console.log("reload 1"); var dati = JSON.parse(response); var html = ''; $.each(dati.contenuto, function (key, value) { console.log(key + ": " + JSON.stringify(value)); let newDate = new Date(value.data_inizio_pubblicazione); const day = newDate.getDate(); const monthIndex = newDate.getMonth(); const year = newDate.getFullYear(); const months_it = [ 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre' ]; const months_en = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; var monthName = ''; if(lang == 'it'){ monthName = months_it[monthIndex]; } else { monthName = months_en[monthIndex]; } const formattedDate = `${day} ${monthName} ${year}`; newDate = newDate.toLocaleDateString(); html += '
  • '; html += '
    '; html += '
    '; html += ''+value.titolo_it+'

    '+value.testo_breve_it+'

    '; html += '
    '+formattedDate+'
    '; html += '
  • '; }); $newItem = $(html); $grid = $('.blog-listing'); $grid.isotope() .append($newItem) .isotope('appended', $newItem); setTimeout(function (){ $grid.isotope('layout'); }, 500); var rowno = row + rowperpage; if (rowno > allcount) { $('.load-more-blogs').hide(); } else { $(".load-more-blogs a").text('Load more'); } }, 100); } }); } else { $('.load-more-blogs button').text("Load more"); setTimeout(function () { $('.immagine-album:nth-child(3)').nextAll('.post').remove(); $("#row").val(0); $('.load-more-blogs button').text("Load more"); }, 2000); } });