PHP Classes

File: tests/multiplier.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Guilherme Blanco  >  pAjax  >  tests/multiplier.php  >  Download  
File: tests/multiplier.php
Role: Example script
Content type: text/plain
Description: Simple multiply calculator 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: 9 years ago
Size: 1,969 bytes


Class file image Download

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

multiply($x, $y) {
$x * $y;

$AJAX = new pAjax;

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

<html xmlns="" lang="en" xml:lang="en">
        <title>Server Multiplier</title>
        <?php $AJAX->showJavaScript(".."); ?>
<script type="text/javascript">
            // Defining Object
            function Multiplier() {

            // Extending AJAX Object on Multiplier
            var _p = Multiplier.prototype = new pAjax;

            // Command action: Action that creates and send the request
            _p.execAction = function () {
                var x = document.getElementById("x").value;
                var y = document.getElementById("y").value;

                // Creates the request
                var oRequest = this.prepare("multiply", pAjaxRequest.GET);
                oRequest.setParam("value1", x);
                oRequest.setParam("value2", y);
                oRequest.execute(pAjaxRequest.ASYNC); // Same as oRequest.execute();

            // Callback: Function that handles the response of request
            // Must be called "onLoad".
            _p.onLoad = function () {
                // Retrieve data from response
                // this.getData() is depreciate, backward compatibility still available
                var data = this.getResponse();
                document.getElementById("z").value = data;
            // Creating a simple Multiplier Object
            var Calc = new Multiplier;

        <input type="text" name="x" id="x" value="2" size="3"> * <input type="text" name="y" id="y" value="3" size="3">
        = <input type="text" name="z" id="z" value="" size="3">

        <input type="button" name="check" value="Calculate" onclick="Calc.execAction(); return false;">