bloqhead
11/6/2013 - 6:48 PM

If the server is still accessible, refresh the page, otherwise, check again in another N seconds. -- Flying Pig Taphouse script for their me

If the server is still accessible, refresh the page, otherwise, check again in another N seconds. -- Flying Pig Taphouse script for their menu. We didn't want to lose their menu on the screen if the internet went down.

var time_to_wait = 600000; // 10 minutes
	
/**
 *	refresh_page ()
 *
 *		Runs an AJAX call to check up on the server before refreshing the page.
 */
function refresh_page () {
	// Let's make the AJAX call to check to see if the server is still available.
	$.ajax({
		url : '<?php echo admin_url( 'admin-ajax.php'); ?>',
		data : {
			action : 'serveraccessible'
		}
	})
		.done(function () {
			// It is! Let's refresh the page to get the latest data.
			window.location = window.location;
		})
		.fail(function() {
			// Oh bummer. Well, let's reset the timer to check again.
			setTimeout('refresh_page()', time_to_wait);
		});
} // function

(function($){
	// Get the ball rolling.
	setTimeout('refresh_page()', time_to_wait);
})(jQuery);