Places to visit in Vietnam

Experience the best Vietnam: Ho Chi Minh City to Halong Bay and more

OVER 35 YEARS EXPERIENCE AWARD WINNING LUXURY HOLIDAYS 100% FINANCIAL PROTECTION

$("#sortTour, #sortTourByCountry, #region_id, #city_id").change(function () { currentPage = 1; shouldScroll = true; // Enable scrolling for filtering fetchTours(currentPage, shouldScroll); }); function fetchTours(page, scrollToTop) { let selectedCountry = '3'; let sortBy = $("#sortTour").val(); let tourType = 'place'; let region_id = $("#region_id").val(); let city_id = $("#city_id").val(); $.ajax({ url: "/api/highlights", method: "GET", data: { page: page, per_page: perPage, country_id: selectedCountry ,type: tourType , region_id:region_id, city_id:city_id}, success: function (response) { $("#search_results").empty(); if (response.tours && response.tours.length > 0) { response.tours.forEach(function (tour) { const baseUrl = window.location.origin; const tourFeaturedImage = tour.featured_image ? baseUrl + '/storage/' + tour.featured_image : "/img/default.png"; const tourDescription = tour.excerpt || ""; const tourUrl = `${tour.final_url.toLowerCase()}`; // Handle blank or null 'tour.type' const toUpperFirst = (str) => { return str .replace(/\w+/g, (match) => match.charAt(0).toUpperCase() + match.slice(1).toLowerCase()); }; const tourTypeText = tour.type && tour.type.trim() ? toUpperFirst(tour.type) : ""; $("#search_results").append(` `); }); } else { $("#search_results").append("

Data not available.

"); } if (scrollToTop) { $("html, body").animate({ scrollTop: $("#HighlightList").offset().top }, 500); } updatePagination(response.pagination); }, error: function (xhr) { console.error("Error fetching tours:", xhr); $("#search_results").empty().append("

Failed to fetch data. Please try again later.

"); }, }); } function updatePagination(pagination) { if (!pagination) { $("#paged").hide(); return; } const currentPage = pagination.current_page; const lastPage = pagination.last_page; const maxVisiblePages = 5; // Number of visible pages before showing "..." $("#paged").empty(); // Add "Previous" button if (currentPage > 1) { $("#paged").append(createPageItem("«", currentPage - 1, false)); } let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2)); let endPage = Math.min(lastPage, currentPage + Math.floor(maxVisiblePages / 2)); // Ensure first page is always shown, but not duplicated if (startPage > 1) { if (startPage > 2) { $("#paged").append(createPageItem(1, 1, currentPage === 1)); $("#paged").append('
  • ...
  • '); // Show "..." if there's a gap } else { startPage = 1; // Fix to make sure page 1 is included } } // Add middle pages (now includes `1` properly) for (let page = startPage; page <= endPage; page++) { $("#paged").append(createPageItem(page, page, currentPage === page)); } // Ensure last page is always shown, but not duplicated if (endPage < lastPage) { if (endPage < lastPage - 1) { $("#paged").append('
  • ...
  • '); // Show "..." if there's a gap } $("#paged").append(createPageItem(lastPage, lastPage, currentPage === lastPage)); } // Add "Next" button if (currentPage < lastPage) { $("#paged").append(createPageItem("»", currentPage + 1, false)); } $("#paged").show(); function createPageItem(text, page, isActive) { const pageItem = $("
  • ") .addClass("pageno") .toggleClass("active", isActive); const pageLink = $("") .attr("href", "#resultbar") .text(text) .attr("data-page", page) .click(function (e) { e.preventDefault(); shouldScroll = true; // Enable scrolling for filtering fetchTours(page, shouldScroll); }); pageItem.append(pageLink); return pageItem; } } }); -->