how do I check if connection to site is lost with jQuery
Hey i want to have a popup that shows up if the user loses connection to my website, i would prefer it to be in jQuery as that's what I'm using, and it seems more light weight on the page
I have this code, but it doesn't seem to work... it should check on document ready then keep trying every 5 seconds
function checkConnection() { $.ajax({ type:"post", url:"http://<?php echo $_SERVER['SERVER_NAME']; ?>/connectionCheck.php", error:function(XMLHttpRequest, textStatus, errorThrown) { alert('you seem to have lost connetion to the site.'); }, success:function(data) { } });
function checkConnection() { $.ajax({ type:"post", url:"http://<?php echo $_SERVER['SERVER_NAME']; ?>/connectionCheck.php", error:function(XMLHttpRequest, textStatus, errorThrown) { hideError(); }, success:function(data) { showError('Page Error!!', 'you seem to have lost connetion to the site.'); } });
okay it worked for a while but now its showing up even if i am connected to the server... even on localhost, has any one got a working code for this...
Bookmarks