I am using javascript functions to interface with an API that use quite a number of jQuery.post calls.
I would like to implement a way of completing a standard action if the response to any .post call meets a set criteria. An example would be a user who leaves the application for a period of time and is logged out on the backend, where the action might be to display a popup login dialog when the API returns a standard JSON object reflecting that the requested action cannot be performed because the user is not logged in, or redirecting to the login screen.
I could, inside every success function executed on the response add, as the first item, a standard function call that would check the returned JSON object and, if it is detected, prompt for re-login.
But adding the same call to lots of functions seems line a maintenance nightmare.
Rather than doing that I was wondering if there is an easy way to extend the jQuery.post function so that it would always interrogate the response for some standard content and based on the content carry our an action or pass it to the success function.