Home > Beginner Scripts, Tutorials > XAJAX is easy

XAJAX is easy

December 17th, 2008

xajax is easy! Just include xajax, register a function (or an object or class method)…

<?php
include './xajax/xajax_core/xajax.inc.php';

$xajax = new xajax();

$rqstAdd =& $xajax->register(XAJAX_FUNCTION, 'doAdd');
$rqstReset =& $xajax->register(XAJAX_FUNCTION, 'doReset');

// set the parameters
$rqstAdd->setParameter(0, XAJAX_JS_VALUE, 39);
$rqstAdd->setParameter(1, XAJAX_JS_VALUE, 571);

$xajax->processRequest();

function doAdd($a, $b)
{
    $response = new xajaxResponse();
    $response->assign('answer', 'innerHTML', $a + $b);
    $response->assign('reset', 'style.display', 'block');
    return $response;
}

function doReset()
{
    $response = new xajaxResponse();
    $response->clear('answer', 'innerHTML');
    $response->assign('reset', 'style.display', 'none');
    return $response;
}

then add a call to the function in your HTML or javascript…

<form action="#" method="post">
<input type="button" onclick="<strong><?php $rqstAdd->printScript(); ?></strong>" id="btnAdd" value="Click Me" />
<input type="button" onclick="<strong><?php $rqstReset->printScript(); ?></strong>" id="btnReset" value="Reset" />
<p id="answer"></p>
</form>

Beginner Scripts, Tutorials

  1. No comments yet.
  1. No trackbacks yet.