Add abort for previous ajax requests

This commit is contained in:
Abhishek Kumar
2022-11-23 13:06:30 +05:30
parent 2b0f42ad6f
commit 9c032e93fc
4 changed files with 13 additions and 6 deletions

View File

@@ -218,7 +218,7 @@ class CategoryControllerCore extends FrontController
public function displayAjaxFilterResults()
{
$response = array('status' => 'ko');
$response = array('status' => false);
$this->display_header = false;
$this->display_footer = false;
@@ -291,10 +291,10 @@ class CategoryControllerCore extends FrontController
$this->context->smarty->assign(array('booking_data' => $booking_data));
$html = $this->context->smarty->fetch('_partials/room_type_list.tpl');
$response['status'] = 'ok';
$response['status'] = true;
$response['html_room_type_list'] = $html;
}
die(json_encode($response));
$this->ajaxDie(json_encode($response));
}
/**

View File

@@ -1061,7 +1061,7 @@ class ProductControllerCore extends FrontController
$response['html_booking_form'] = $html;
}
die(json_encode($response));
$this->ajaxDie(json_encode($response));
}
public function displayAjaxCheckRoomAvailabilityAndRate()

View File

@@ -184,7 +184,7 @@ $(document).ready(function()
dataType: 'JSON',
data: data,
success: function (response) {
if (response.status == 'ok') {
if (response.status) {
$('#category_data_cont').html(response.html_room_type_list);
}
}

View File

@@ -1170,7 +1170,9 @@ $(document).ready(function() {
});
var BookingForm = {
currentRequest: null,
init: function() {
this.currentRequest = null;
BookingForm.initDatepicker();
},
initDatepicker: function() {
@@ -1259,7 +1261,7 @@ var BookingForm = {
return data;
},
refresh: function() {
$.ajax({
BookingForm.currentRequest = $.ajax({
url: product_controller_url,
type: 'POST',
headers: { 'cache-control': 'no-cache' },
@@ -1269,6 +1271,11 @@ var BookingForm = {
ajax: true,
action: 'refreshBookingForm',
}, BookingForm.getFormData()),
beforeSend: function() {
if(BookingForm.currentRequest != null) {
BookingForm.currentRequest.abort();
}
},
success: function(response) {
if (response.status == true) {
$('.booking-form').replaceWith(response.html_booking_form);