- 论坛徽章:
- 0
|
看了XAJAX的HELLOWORD,所以想加上SMARTY试一下
但是不成功,不知道问题在什么地方
发出代码,麻烦各位帮我看看,谢谢
hello.php
- <?php
- // using xajax version 0.1 beta4
- require('main.php');
- require_once('xajax.inc.php');
- $xajax = new xajax();
- function helloWorld($isCaps)
- {
- if ($isCaps)
- $text = "HELLO WORLD!";
- else
- $text = "Hello World!";
-
- $objResponse = new xajaxResponse();
- $objResponse->addAssign("div1","innerHTML",$text);
-
- return $objResponse->getXML();
- }
- function setColor($sColor)
- {
- $objResponse = new xajaxResponse();
- $objResponse->addAssign("div1","style.color", $sColor);
- return $objResponse->getXML();
- }
- //$xajax->debugOn();
- $xajax->registerFunction("helloWorld");
- $xajax->registerFunction("setColor");
- $xajax -> processRequests();
- $xajaxHead = $xajax -> printJavascript();
- $Assigns = array(
- 'xajaxHead' => $xajaxHead,
- );
-
- $tpl->assign('Assigns', $Assigns);
- $tpl->display('hello1.htm');
- ?>
复制代码
模板 hello.htm
- <html>
- <head>
- <title>xajax example</title>
- <{$Assigns.xajaxHead}>
- </head>
- <body style="text-align:center;">
- <div id="div1" name="div1"> </div>
- <br/>
-
- <button onclick="xajax_helloWorld(0)" >Click Me</button>
- <button onclick="xajax_helloWorld(1)" >CLICK ME</button>
- <select id="colorselect" name="colorselect" onchange="xajax_setColor(document.getElementById('colorselect').value);">
- <option value="black" selected="selected">Black</option>
- <option value="red">Red</option>
- <option value="green">Green</option>
- <option value="blue">Blue</option>
- </select>
- <script type="text/javascript">
- xajax_helloWorld(0);
- xajax_setColor(document.getElementById('colorselect').value);
- </script>
- </body>
- </html>
复制代码
main.php这个是SMARTY设置
- <?php
- include "class/Smarty.class.php";
- define('__SITE_ROOT', 'D:/www/test');
- //require_once "includes/functions.php";
- //require_once "includes/include.php";
- $tpl = new Smarty();
- $tpl->template_dir = __SITE_ROOT . "/templates/";
- $tpl->compile_dir = __SITE_ROOT . "/templates_c/";
- $tpl->config_dir = __SITE_ROOT . "/configs/";
- $tpl->cache_dir = __SITE_ROOT . "/cache/";
- $tpl->left_delimiter = '<{';
- $tpl->right_delimiter = '}>';
- ?>
复制代码
[ 本帖最后由 HonestQiao 于 2005-12-22 23:57 编辑 ] |
|