I am working on a asp.net mvc3 application.
I have this Jquery function
function CheckSession() {
$.ajax({
type: 'POST',
url: '@Url.Action("CheckSession", "Home")',
success: function (isAvailable) {
return isAvailable;
},
complete: function (owner) {
},
error: function (owner) {
alert('Error Getting session');
return false;
}
});
}
Basically what this session does is call an action from the HomeController that action will return true or false.
What I want to do is this,
Before every ajax call in the application I want to first use this function. and if it return true we procede with the call, else we dont do anything.
Is there a way to do this Without having to go through all the code and call it before every ajax call
I know this can be done by calling it before every ajax and testing the return, but i have tons of ajax calls.
What I’m looking for is an event handler that fires before any ajax call is made
something like this:
$(ajax).beforeCall(function (event) {
if (CheckSession()){
event.ProceedWithCall;
}
else {
//Stop the call;
return false;
}
});
You can use
ajaxSetupand set thebeforeSendfunction like this:beforeSenddocs:ajaxSetupdocs: