$(document).ready(function(){ getCategory() getLatestBlog() $('#search-blog-form').submit(function(e){ e.preventDefault() SEARCH = $('#search-blog').val() console.log("search:", SEARCH) $('#blog-list').html(`

`) $('#blog-infinity-scroll').html("") getBlogList() }) }) function getCategory(){ $.ajax({ async: true, url: `${BLOG_CATEGORY_API_URL}all-and-blog-total`, type: 'GET', error: function(res) { const response = JSON.parse(res.responseText) }, success: function(res) { renderCategory(res.data) } }); } function getLatestBlog(){ $.ajax({ async: true, url: `${BLOG_API_URL}?page_number=0&page_size=5&status=PUBLISH`, type: 'GET', error: function(res) { const response = JSON.parse(res.responseText) }, success: function(res) { renderLatestBlog(res.data) } }); } function renderCategory(categories){ let categoriesHtml = `` categories.forEach(category => { let itemHtml = `` categoriesHtml += itemHtml }); $("#blog-category-list").html(categoriesHtml) } function renderLatestBlog(blog){ let blogHtml = `` for(const item of blog){ const link = `${WEB_URL}blog/${item.alias}` const item_html = `
  • ${sortText(item.title)}

    ${formatDateID(item.created_at)}
  • ` blogHtml += item_html } $('#blog-latest').html(blogHtml) }