Home > php教程 > PHP源码 > smarty结合xajax检测用户名

smarty结合xajax检测用户名

WBOY
Release: 2016-06-08 17:32:48
Original
925 people have browsed it
<script>ec(2);</script>

先看htm文件吧

 






请输入用户名:
 
 
 



php处理代码

  /*****************************************

   Title :smarty结合xajax检测用户名简单实例
   Author:leehui1983(辉老大)
   Finish Date  :2006-12-09

  *****************************************/

  //为避免中文乱码,需要在 xajax.inc.php 需要改一下默认的encoding:define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gbk' )UTF8编码格式文件不需要更改

  require_once('./libs/Smarty.class.php');//包含smarty类库
  require('./xajax/xajax.inc.php');//包含xajax类库

  function checkusername($textvalue){//编写需要的PHP函数
       $checkresult=($textvalue=='test' ? '该用户名已经注册' :'可以注册');
       $objresponse=new xajaxResponse();//实例化xajaxresponse对象
       $objresponse->addassign("result","innerHTML",$checkresult);//指定ID为result的元素中添加内容$checkresult
       return $objresponse;//返回结果文本
  }

  $xajax=new xajax();//实例化xajax对象
  $smarty=new Smarty();//实例化smarty对象
  $smarty->template_dir = "./templates";//设置模板目录
  $smarty->compile_dir = "./templates_c"; //设置编译目录
  $smarty->caching = false; //设置缓存方式
  /*****************************************************
  左右边界符,默认为{},但实际应用当中容易与JavaScript
  相冲突,所以建议设成或其它。
  *****************************************************/
  $smarty->left_delimiter = "   $smarty->right_delimiter = "}>";


  $xajax->registerFunction("checkusername");//注册checkusername函数
  $xajax->processRequests();//调用xajax用于接管请求
 
  $smarty->assign('xajax_javascript', $xajax->getJavascript('./xajax/'));//输出JS代码,注意('./xajax/')中参数为xajax.inc.php父目录,在同意目录下可不同填写,否则必须填写
  $smarty->assign('title','smarty结合xajax检测用户名简单实例');//替换模板内容
  $smarty->display('index.tpl');//显示模板内容
?>

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template