fix bug freeze js

This commit is contained in:
root 2026-01-14 12:05:11 +00:00
parent 0a537d9500
commit 2b37be5f51
1 changed files with 38 additions and 8 deletions

View File

@ -117,22 +117,52 @@ class="bi bi-chevron-right"></i></a></li>
// Fungsi Ambil Data (AJAX) // Fungsi Ambil Data (AJAX)
function fetchBuket(url = "{{ route('pesan.buket') }}") { function fetchBuket(url = "{{ route('pesan.buket') }}") {
let urlObj = new URL(url, window.location.origin);
let path = urlObj.pathname;
let params = {
keyword: $('#input-search').val(),
kategori: selectedCat,
ukuran: selectedSize,
min_price: $('#input-min').val(),
max_price: $('#input-max').val()
};
Object.keys(params).forEach(key => {
if (!params[key]) delete params[key];
});
let searchParams = new URLSearchParams(urlObj.search);
let pageParam = searchParams.get('page');
if (pageParam) {
params.page = pageParam;
}
let newUrl = path + '?' + new URLSearchParams(params).toString();
if (window.location.protocol === 'https:') {
newUrl = 'https://' + window.location.host + newUrl;
}
console.log('Fetching URL:', newUrl);
$.ajax({ $.ajax({
url: url, url: newUrl,
type: "GET", type: "GET",
data: {
keyword: $('#input-search').val(),
kategori: selectedCat,
ukuran: selectedSize,
min_price: $('#input-min').val(),
max_price: $('#input-max').val()
},
beforeSend: function() { beforeSend: function() {
$('#product-container').css('opacity', '0.5'); $('#product-container').css('opacity', '0.5');
}, },
success: function(data) { success: function(data) {
$('#product-container').html(data); $('#product-container').html(data);
$('#product-container').css('opacity', '1'); $('#product-container').css('opacity', '1');
},
error: function(xhr, status, error) {
console.error('AJAX Error:', status, error);
$('#product-container').css('opacity', '1');
if (xhr.status === 0 || error === 'error') {
window.location.reload();
}
} }
}); });
} }