Fork me on GitHub

A simple example

This is a simple and fully functional example, the Xajax way, to show all the steps of how Jaxon works.

// 0. Jaxon is installed with Composer. Setup the autoloading.

use Jaxon\Jaxon;
use function Jaxon\jaxon;

// 1. Define your functions or classes.
function hello_world($isCaps)
    // Create and use a Jaxon response.
    $response = jaxon()->newResponse();
    $text = ($isCaps) ? 'HELLO WORLD!' : 'Hello World!';
    $response->assign('div1', 'innerHTML', $text);
    return $response;

// 2. Initialize and configure the library.
$jaxon = jaxon();

// 3. Register your functions or classes.
$jaxon->register(Jaxon::CALLABLE_FUNCTION, "hello_world");

// 4. Process the request.
    // This function will return the response and exit.

// 5. Insert the Jaxon codes in your HTML page.
<!DOCTYPE html>
<html lang="en">
    <title>Jaxon Examples</title>
    <div id="div1">&nbsp;</div>
    <input type="button" value="Say Hello" onclick="jaxon_hello_world(true)" />
<!-- Jaxon CSS -->
<?php echo $jaxon->getCss(), "\n"; ?>
<!-- Jaxon JS -->
<?php echo $jaxon->getJs(), "\n"; ?>
<!-- Jaxon script -->
<?php echo $jaxon->getScript(), "\n"; ?>