Look at the HTM file first.
<title><{$title}></title>
<{$xajax _javascript}><{* make Smarty support xajax*}>
<body>
<form name= "Check" >
Please enter user name:
<input type= "text" name= "username"/>
<input type= "button" name= "button" value= "Check user name"/>
<div id= "Result" ></div>
</form>
</body>
PHP Processing Code
<?php
/*****************************************
Title:smarty combined with Xajax to detect a simple instance of user name
author:leehui1983 (leader of FAI)
Finish date:2006-12-09
*****************************************/
In order to avoid Chinese garbled, need to change the default Encoding:define (' xajax_default_char_encoding ', ' GBK ') UTF8 code format file in xajax.inc.php need not change
Require_once ('./libs/smarty.class.php ');//containing Smarty class library
Require ('./xajax/xajax.inc.php ');//containing Xajax class library
function Checkusername ($textvalue) {//php functions needed to write
$checkresult = ($textvalue = = ' Test '? ' <font color=red> the username has been registered </font> ': ' <font color=red> can be registered </font> ');
$objresponse =new xajaxresponse ();//Instantiate Xajaxresponse Object
$objresponse->addassign ("result", "InnerHTML", $checkresult);//add content to the element that specifies the ID as result $checkresult
return $objresponse//Returns the result text
}
$xajax =new xajax ()//Instantiate Xajax object
$smarty =new smarty ()//Instantiate Smarty Object
$smarty-> Template_dir = "./templates";//Set template directory
$smarty->compile_dir = "./templates_c";//Set compilation directory
$ Smarty->caching = false; Set caching method
/*****************************************************
left-right border characters, default to {}, But the actual application is easy to conflict with JavaScript
, so it is recommended to set <{}> or other.
*****************************************************/
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$xajax->registerfunction ("Checkusername");//Register Checkusername function
$xajax->processrequests ();//Call Xajax to take over the request
$smarty->assign (' Xajax_javascript ', $xajax->getjavascript ('./xajax/'))//Output JS Code, note ('./xajax/') The parameter is xajax.inc.php parent directory, in the consent directory can be different fill in, or you must fill in
$smarty->assign (' title ', ' Smarty combination xajax detect user name simple instance ');/Replace template contents
$smarty->display (' index.tpl ');//Display template contents
?>