I'm trying to find a good way to achieve this. If you have any other better suggestions, I'm all ears.
Basically, my site has a bunch of ajax calls. However, I feel like these should be called in a such a way so I don't have to repeat code. Especially the beforeSend method. I don't want to have to type the check methods below everytime. How do I approach this so I dont have to type the check methods everytime? They can have different methods added on to the ones mentioned below, but the 2 below will ALWAYS have to be called. I'm even okay instantiating the ajax call in a different way.
Currently, I have this all over the place in different flavors:
var Params = {};
Params.type = "POST";
Params.url = '/this/is/my/url';
Params.cache = false;
Params.timeout = 180000;
Params.processData = true;
Params.data = {
action: "ajax",
method: "coolMethod",
};
Params.dataType = "json";
Params.beforeSend = function () {
checkIfUserHasLoggedOut();
checkSomeOtherThings();
};
Params.error = function (xhr, status, error) {
};
Params.success = function (data) {
};