catching lost connection or lost authentication event using jQuery
<p>I read a couple of articles here that inspired my solution but wondering if i'm doing it the right way.</p>

<p>What I did was to create an event that catches an jQuery ajax error:</p>

<pre><code>$('body').ajaxError(function(xmlHttpRequest, ajaxOptions, error) {
       if (!locked) CheckUserAuthentication();
});
</code></pre>

<p>Then the CheckUserAuthentication() goes through another ajax call to a webservice that attempts to check if authentication is still active. if it returns a value that it needs to re-login, I then prompt a modal box that displays a log-in form. If the ajax call fails, then it's safe to assume that internet connection has been lost, so I prompt another modal box that displays a message and a js loop that checks the connection again in intervals.</p>

<p>My first concern is that the event code above actually repeats triggering itself if it reaches to the second ajax error making it a repeating loop. So I made a variable that sets a boolean whether to lock the event to prevent this.</p>

<p>My questions:</p>

<p>1) Am I doing it correctly?</p>

<p>2) If yes, then can I dispose an ajax exception so that i don't need to lock the .ajaxError event from re-triggering?</p>

<p>3) Any other ideas much efficient that what I'm doing?</p>

<p>I appreciate all the help!</p>
