Use 'online' and 'offline' events to display error messages

This commit is contained in:
Abhishek Kumar
2024-04-02 13:16:04 +05:30
parent 793e15e8c3
commit f74e4b665a
4 changed files with 21 additions and 10 deletions

View File

@@ -482,7 +482,7 @@ var ajaxCart = {
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest.readyState == 0) {
if (!onlineFlag) {
showErrorMessage(no_internet_txt);
} else {
var error = "Impossible to add the room to the cart.<br/>textStatus: '" + textStatus + "'<br/>errorThrown: '" + errorThrown + "'<br/>responseText:<br/>" + XMLHttpRequest.responseText;
@@ -620,7 +620,7 @@ var ajaxCart = {
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest.readyState == 0) {
if (!onlineFlag) {
showErrorMessage(no_internet_txt);
} else {
var error = "Impossible to add the room to the cart.<br/>textStatus: '" + textStatus + "'<br/>errorThrown: '" + errorThrown + "'<br/>responseText:<br/>" + XMLHttpRequest.responseText;
@@ -694,8 +694,8 @@ var ajaxCart = {
deleteProductFromSummary(idProduct + '_' + idCombination + '_' + customizationId + '_' + idAddressDelivery);
}*/
},
error: function(jqXHR) {
if (jqXHR.readyState == 0) {
error: function() {
if (!onlineFlag) {
showErrorMessage(no_internet_txt);
} else {
var error = 'ERROR: unable to delete the product';

View File

@@ -24,6 +24,7 @@
*/
//global variables
var responsiveflag = false;
var onlineFlag = true;
@@ -494,3 +495,11 @@ function showErrorMessage(msg) {
function showNoticeMessage(msg) {
$.growl.notice({ title: "", message:msg});
}
window.addEventListener('online', function () {
onlineFlag = true;
});
window.addEventListener('offline', function () {
onlineFlag = false;
});

View File

@@ -482,7 +482,7 @@ var ajaxCart = {
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest.readyState == 0) {
if (!onlineFlag) {
showErrorMessage(no_internet_txt);
} else {
var error = "Impossible to add the room to the cart.<br/>textStatus: '" + textStatus + "'<br/>errorThrown: '" + errorThrown + "'<br/>responseText:<br/>" + XMLHttpRequest.responseText;
@@ -620,7 +620,7 @@ var ajaxCart = {
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest.readyState == 0) {
if (!onlineFlag) {
showErrorMessage(no_internet_txt);
} else {
var error = "Impossible to add the room to the cart.<br/>textStatus: '" + textStatus + "'<br/>errorThrown: '" + errorThrown + "'<br/>responseText:<br/>" + XMLHttpRequest.responseText;
@@ -694,8 +694,8 @@ var ajaxCart = {
deleteProductFromSummary(idProduct + '_' + idCombination + '_' + customizationId + '_' + idAddressDelivery);
}*/
},
error: function(jqXHR) {
if (jqXHR.readyState == 0) {
error: function() {
if (!onlineFlag) {
showErrorMessage(no_internet_txt);
} else {
var error = 'ERROR: unable to delete the product';

View File

@@ -1466,10 +1466,12 @@ var BookingForm = {
}
}
},
complete: function(jqXHR, textStatus) {
if (textStatus == 'error') {
error: function() {
if (!onlineFlag) {
showErrorMessage(no_internet_txt);
}
},
complete: function() {
$('.book_now_submit').prop('disabled', false).find('span:not(#booking_action_loader)').show();
$('#booking_action_block').find('#booking_action_loader').removeClass('active');
}