Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/multiplier.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 2006-05-31 20:29
Size: 1,969 bytes
 

Contents

Class file image Download
<?php

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


function 
multiply($x$y) {
    return 
$x $y;
}


$AJAX = new pAjax;
$AJAX->disableDomainProtection();
$AJAX->enableExportProtection();
$AJAX->export("multiply");
$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>Server Multiplier</title>
        <?php $AJAX->showJavaScript(".."); ?>
        <script type="text/javascript">
            // Defining Object
            function Multiplier() { 
                pAjax.call(this);
                pAjax.setDebugMode(true);
            }


            // 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;
        </script>
    </head>

    <body>
        <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;">
    </body>
</html>