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: 10 years ago
Size: 2,071 bytes


Class file image Download

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

doesNothing() {
"Guilherme Blanco";

$AJAX = new pAjax;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="" lang="en" xml:lang="en">
        <title>Ajax Events Test</title>
        <?php $AJAX->showJavaScript(".."); ?>
<script type="text/javascript">
            function Tester() {
                // Needed, otherwise onInit event will be never executed!
            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());
        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();" />