Location: PHPKode > scripts > pAjax > pajax/tests/multiplier.php

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

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

$AJAX = new pAjax;

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

<html xmlns="http://www.w3.org/1999/xhtml" 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;">
Return current item: pAjax