Location: PHPKode > scripts > pAjax > pajax/tests/events.php
<?php

require_once "../class.pAjax.php";


function doesNothing() {
	return "Guilherme Blanco";
}

$AJAX = new pAjax;
$AJAX->disableDomainProtection();
$AJAX->enableExportProtection();
$AJAX->export("doesNothing");
$AJAX->handleRequest();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title>Ajax Events Test</title>
        <?php $AJAX->showJavaScript(".."); ?>
		<script type="text/javascript">
			function Tester() {
				// Needed, otherwise onInit event will be never executed!
				pAjax.call(this);
				pAjax.setDebugMode(true);
			}
			
			
			var _p = Tester.prototype = new pAjax;
			
			_p.execAction = function () {
				var oRequest = this.prepare("doesNothing", pAjaxRequest.POST);
				oRequest.setParam("name", "value");
                oRequest.execute(pAjaxRequest.ASYNC); // Default parameter is ASYNC
			}
			
			_p.onInit = function () {
				alert('Event onInit: Object AJAX initialized!');
			}
			
			_p.onCreate = function () {
				alert('Event onCreate: Object AJAX created XmlHttpRequest Object!');
			}		
			
			_p.onChange = function () {
				alert('Event onChange: Object AJAX changed its state - ' + this.getReadyState());
			}			
			
			_p.onLoad = function () {
				alert('Event onLoad: Object AJAX loaded with data - ' + this.getResponse());
			}
		</script>
	</head>
	
	<body>
		Does nothing, just show all events being called<br />
		- <b>onInit</b>: Called when Object AJAX is created (or even created by extended classes)<br />
		- <b>onCreate</b>: Called when Object XmlHttpRequest is created while calling prepare method<br />
		- <b>onChange</b>: Called when a request changes its readyState value<br />
		- <b>onLoad</b>: Called when a request has been finished its request and recieved any have content<br />
		<br />
		<input type="button" value="Test!" onclick="(new Tester()).execAction();" />
	</body>
</html>
Return current item: pAjax