I have the code which i am running to check that my session is check before any ajax call is made, i have added a successCheck
in the code to check if its not going recursive, but it shows in network panel, it works but not in the console.
any idea what i am doing wrong here
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
console.log(options);
// Check if the request is an AJAX call
if (options.type.toLowerCase() !== "post" && options.type.toLowerCase() !== "get") {
return;
}
// Check if the sessionCheck option is present
if (options.sessionCheck === false) {
console.log('hello');
return;
}
// Run the session expiration check before each AJAX call
checkSessionBeforeAjax(jqXHR);
});
function checkSessionBeforeAjax(jqXHR) {
// Make an AJAX call to check if the session has expired
$.ajax({
url: "checkSession.cfm",
type: "POST",
sessionCheck: false,
success: function(response) {
var _resp = $.parseJSON(response);
console.log(_resp);
var status = _resp[1];
alert(status);
if (status === "expired") {
// Display a popup message to the user with a high z-index
customSwal('success',_resp[1],
() => {
window.location.href = 'logout.cfm';
}
);
}
}
});
}
there are many ajax calls in my code, which runs one after one, so this check is for those and it runs before each ajax request, i was also wondering if this could just check the first call i am making and show a sweetAlert and halt all others if the alert is shown and user navigates to logout screen. on click ok OK button.