Xajax 0.5: Tips and Tricks: Using multiple request URIs






Xajax 0.5: Tips and Tricks: Using multiple request URIs

[edit] Register function

1) Create a global xajax include file

<?php
// Requiring the xajax core file
require_once "xajax/xajax_core/xajax.inc.php";

// Defining the xajax object
$xajax = new xajax();
?>

2) Create a common php file with the standard xajax calls:

<?php
// Common file

// Registering our function, remember that the URI must be a string: "handler.php"
$xajax->register(XAJAX_FUNCTION, 'myFunctionA', array('URI' => "\"handler.php\""));
?>

3) Create a handler file

<?php
// Handler

// Require the ajax global file
require_once "xajax_include.php";

// Require the common file for this handler
require_once "common.php";

// Our function
function myFunctionA($givenParameters) {

	// new xajaxResponse Object
	$objResponse = new xajaxResponse();

        // Process

	return $objResponse;
}

// Let xajax process our request
$xajax->processRequest();
?>

4) Create your main php file

<?php
// Require the xajax global file
require_once "xajax_include.php";

// Require the Common file for this page
require_once "common.php";
?>
<!DOCTYPE ... />
<html>
    <head>
        <?php $xajax->printJavascript(); ?>
        ...
    </head>
    etc ...

5) call functions like always:

<a href='#' onclick='xajax_myFunctionA(); return false;'>

6) Repeat this for multiple files, with each their own common and handler file. Remember to include each common file in order to register all your functions.

Author: WalkingSoul - Jeffrey - 2008/01/02