PHP Xajax Loading Message – Reverse Ajax

Saturday, February 20, 2010 22:23
Posted in category Ajax - Reverse Xaja
<?php

	include './xajax/xajax_core/xajax.inc.php'; //include the xajax libraries

	 function loading_function(){

			new object response object 

			$objResponse = new xajaxResponse();

			sleep(2); // Pretend to load some data

			$objResponse->alert("Loading Complete"); // Display an alert when Task is completed

			return $objResponse; // Return Object Response
		}

		 $xajax = new xajax(); // Xajax Object 

		 $xajax->registerFunction('loading_function'); // Register loading_function

		 $xajax->processRequest(); // Process the Request

		 $xajax_js = $xajax->getJavascript('/xajax'); // Xajax javascript into a Variable
?>

Now Calling the function in HTML.

<html>
<head>
<?php echo $xajax_js; ?>

<script type="text/javascript">
  // Load/Call Reverse Ajax
	xajax.callback.global.onRequest = function() {xajax.$('loading').style.display = 'block';}
  xajax.callback.global.beforeResponseProcessing = function() {xajax.$('loading').style.display='none';}
</script>

<style type="text/css">
	#loading {
    width: 200px;
    height: 100px;
    display: none;

    font-weight: bold;
    font-size: large;

    position: absolute;
    top: 25%;
		left: 50%;

		margin-left: -100px;
    }
</style>
</head>
<!-- Please include loading.gif image to display proper resutls -->
<body>
   <div id="loading"><img src="/loading.gif" alt="loading" /> Loading...</div>
	 <input type="button" onclick="xajax_loading_function();" value="My Function" />
</body>
</html>
  • Share/Bookmark
You can leave a response, or trackback from your own site.

Leave a Reply