How to detect client call to server either via page load or ajax in Javascript?
<p>I've used cordova to build a mobile app that sits entirely on the server side. This results in bad experience when the user is offline and interacts with the app. I'd like to detect when the app is about to call the server and alert the user that they are offline.</p>

<p>I have cordova-plugin-network-information so I know when a client is offline. I plan to handle the offline case when I know the app is going to be calling the server. The challenge is to do so in an elegant and clean way.</p>

<p>My app has both synchronous page loads as well as ajax calls. The brute force way would be to find all such calls and handle them with offline alerting.</p>

<p>Is there a way to detect a call to server (either via page load or ajas call) in Javascript so I can centralize offline handling in one place?</p>