fix bug freeze js
This commit is contained in:
parent
0a537d9500
commit
2b37be5f51
|
|
@ -117,22 +117,52 @@ class="bi bi-chevron-right"></i></a></li>
|
|||
|
||||
// Fungsi Ambil Data (AJAX)
|
||||
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({
|
||||
url: url,
|
||||
url: newUrl,
|
||||
type: "GET",
|
||||
data: {
|
||||
keyword: $('#input-search').val(),
|
||||
kategori: selectedCat,
|
||||
ukuran: selectedSize,
|
||||
min_price: $('#input-min').val(),
|
||||
max_price: $('#input-max').val()
|
||||
},
|
||||
beforeSend: function() {
|
||||
$('#product-container').css('opacity', '0.5');
|
||||
},
|
||||
success: function(data) {
|
||||
$('#product-container').html(data);
|
||||
$('#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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue