1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
<?php
/*
File: helloworld.php
Test / example page demonstrating the basic xajax implementation.
Title: Hello world sample page.
Please see <copyright.inc.php> for a detailed description, copyright
and license information.
*/
/*
@package xajax
@version $Id: helloworld.php 362 2007-05-29 15:32:24Z calltoconstruct $
@copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson
@license http://www.xajaxproject.org/bsd_license.txt BSD License
*/
/*
Section: Standard xajax startup
- include <xajax.inc.php>
- instantiate main <xajax> object
*/
require ('../xajax_core/xajax.inc.php');
$xajax = new xajax();
/*
- enable deubgging if desired
- set the javascript uri (location of xajax js files)
*/
//$xajax->configure('debug', true);
$xajax->configure('javascript URI', '../');
/*
Function: helloWorld
Modify the innerHTML of div1.
*/
function helloWorld($isCaps)
{
if ($isCaps)
$text = 'HELLO WORLD!';
else
$text = 'Hello World!';
$objResponse = new xajaxResponse();
$objResponse->assign('div1', 'innerHTML', $text);
return $objResponse;
}
/*
Function: setColor
Modify the style.color of div1
*/
function setColor($sColor)
{
$objResponse = new xajaxResponse();
$objResponse->assign('div1', 'style.color', $sColor);
return $objResponse;
}
/*
Section: Register functions
- <helloWorld>
- <setColor>
*/
$reqHelloWorldMixed =& $xajax->registerFunction('helloWorld');
$reqHelloWorldMixed->setParameter(0, XAJAX_JS_VALUE, 0);
$reqHelloWorldAllCaps =& $xajax->registerFunction('helloWorld');
$reqHelloWorldAllCaps->setParameter(0, XAJAX_JS_VALUE, 1);
$reqSetColor =& $xajax->registerFunction('setColor');
$reqSetColor->setParameter(0, XAJAX_INPUT_VALUE, 'colorselect');
/*
Section: processRequest
This will detect an incoming xajax request, process it and exit. If this is
not a xajax request, then it is a request to load the initial contents of the page
(HTML).
Everything prior to this statement will be executed upon each request (whether it
is for the initial page load or a xajax request. Everything after this statement
will be executed only when the page is first loaded.
*/
$xajax->processRequest();
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<!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" xml:lang="en" lang="en">
<head>
<title>xajax example</title>
<?php
// output the xajax javascript. This must be called between the head tags
$xajax->printJavascript();
?>
<script type='text/javascript'>
/* <![CDATA[ */
window.onload = function() {
// call the helloWorld function to populate the div on load
<?php $reqHelloWorldMixed->printScript(); ?>;
// call the setColor function on load
<?php $reqSetColor->printScript(); ?>;
}
/* ]]> */
</script>
</head>
<body style="text-align:center;">
<div id="div1"> </div>
<br/>
<button onclick='<?php $reqHelloWorldMixed->printScript(); ?>' >Click Me</button>
<button onclick='<?php $reqHelloWorldAllCaps->printScript(); ?>' >CLICK ME</button>
<select id="colorselect" name="colorselect"
onchange='<?php $reqSetColor->printScript(); ?>;'>
<option value="black" selected="selected">Black</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
</body>
</html>
|