Ec (2); & lt ;? Php & nbsp; **************************************** * & nbsp; & nbsp; Title: smarty combined with xajax to detect simple instances of user names & nbsp; Author: leehui1983 (huibo) & nbsp; FinishDate & nbsp;: 2006-12-09 & nbsp; * script ec (2); script
/*************************************** **
Title: Combined with xajax, smarty detects simple user name instances
Author: leehui1983 (Boss Hui)
Finish Date: 2006-12-09
**************************************** */
// To avoid Chinese garbled characters, you need to modify the default encoding in xajax. inc. php: define ('xajax _ DEFAULT_CHAR_ENCODING ', 'gbk') UTF8 encoding format file.
Require_once ('./libs/Smarty. class. php'); // contains the smarty class library
Require ('./xajax. inc. php'); // contains the xajax class library
Function checkusername ($ textvalue) {// compile the required PHP function
$ Checkresult = ($ textvalue = 'test '? 'The user name has been registered ': 'registration ');
$ Objresponse = new xajaxResponse (); // instantiate the xajaxresponse object
$ Objresponse-> addassign ("result", "innerHTML", $ checkresult); // add content to the element whose ID is result. $ checkresult
Return $ objresponse; // return result text
}
$ Xajax = new xajax (); // instantiate an xajax object
$ Smarty = new Smarty (); // instantiate a smarty object
$ Smarty-> template_dir = "./templates"; // set the template directory
$ Smarty-> compile_dir = "./templates_c"; // set the compilation directory
$ Smarty-> caching = false; // sets the cache mode.
/*************************************** **************
Left and right boundary characters. The default value is {}.
Conflict, so it is recommended to set it to <{}> or another.
**************************************** *************/
$ Smarty-> left_delimiter = "<{";
$ Smarty-> right_delimiter = "}> ";
$ Xajax-> registerFunction ("checkusername"); // register the checkusername Function
$ Xajax-> processRequests (); // call xajax to take over the request
$ Smarty-> assign ('xajax _ javascript ', $ xajax-> getJavascript ('. /xajax/'); // output JS Code, note ('. the parameter in/xajax/') is xajax. inc. php parent directory, which can be entered differently under the consent directory; otherwise, it must be entered
$ Smarty-> assign ('title', 'smarty combined with xajax detection username simple instance'); // replace template content
$ Smarty-> display ('index. tpl '); // display template content
?>
<{$ Title}>
<{$ Xajax_javascript}> <{* enabling smarty to support xajax *}>