One of the most simple but important parts of xajax is providing a 'Loading...' message as visual feedback for when xajax is doing a server call. xajax provides two Javascript functions that you can override to do this: xajax.loadingFunction() and xajax.doneLoadingFunction()
In this tutorial, we'll show you how to create a loading message to 'wow' your friends and impress your enemies. Prepare for battle!
First we'll set up a simple xajax page that has a really slow function in it.
<?php
require("xajax.inc.php");
function slow_function()
{
$objResponse = new xajaxResponse();
sleep(2); //we'll do nothing for two seconds
$objResponse->addAlert("All done");
return $objResponse;
}
$xajax = new xajax();
$xajax->registerFunction('slow_function');
$xajax->processRequests();
?><html>
<head>
<title>Loading Bar Demo</title>
<? $xajax->printJavascript(); ?>
</head>
<body>
<input type="button" onclick="xajax_slow_function();" value="Slow Function" />
</body>
</html>
So now we've got the slow function and corresponding button, try clicking the button and see how painful it is that there's no feedback. Sucks don't it?