PHP Classes

File: tests/events.php

Recommend this page to a friend!
  Classes of Guilherme Blanco   pAjax   tests/events.php   Download  
File: tests/events.php
Role: Example script
Content type: text/plain
Description: Events test
Class: pAjax
Do RPC calls from the browser without page reloads
Author: By
Last change: - Updated tests to allow working with disabled domain protection and with
enabled export protection
Date: 18 years ago
Size: 2,071 bytes
 

Contents

Class file image Download
<?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>