下载首页下载分类最近更新排 行 榜国产软件国外软件汉化补丁本站论坛BT下载页
  • 设为首页
  • 收藏本站
  • 联系我们
您的位置:首页网页制作JS/Ajax → Xajax中文手册(第一版)
Xajax中文手册(第一版)
出处:本站整理 作者:佚名 日期:2007-5-7 12:12:09 人气: [ ]
如何在我的PHP脚本之中使用xajax?
Xajax的设计是如此的富有特色,以至于不管是已有的web程序还是新的项目,它都能够被极其简单的部署和应用. 仅仅需要七步,你就可以在几乎任何PHP脚本之中加入xajax的强大功能:
How do I use xajax in my PHP script?
xajax is designed to be extremely easy to implement in both existing web applications as well as new projects. You can add the power of xajax to nearly any PHP script in seven easy steps:
  1. 包含xajax类库:
require_once("xajax.inc.php");
  1. 实例化xajax 对象:
$xajax = new xajax();
  1. 注册你需要通过xajax调用的PHP函数的名称:
$xajax->registerFunction("myFunction");
  1. 编写注册的PHP函数,并且在函数之中使用xajaxResponse 对象返回XML指令:
function myFunction($arg)
{
   // 对$arg做一些基本处理例如从数据库检索数据
   // 然后把结果赋值给变量,例如$newContent
  
   // 实例化xajaxResponse 对象
   $objResponse = new xajaxResponse();
  
   // 添加指令到响应之中,用于指派
   //指定元素(例如id="SomeElementId")的innerHTML属性的新的内容
   $objResponse->addAssign("SomeElementId","innerHTML", $newContent);
  
   //返回xajaxResponse 对象生成的XML响应
   return $objResponse->getXML();
}
  1. 在你的脚本输出任何信息之前,调用xajax用于接管请求:
$xajax->processRequests();
  1. 在页面的 <head></head> 标签之间, 告诉xajax生成所必需的JavaScript:
<?php $xajax->printJavascript(); ?>
  1. 在程序中,从JavaScript事件或者函数调用前面注册的函数:
<div id="SomeElementId"></div>
<button onclick="xajax_myFunction(SomeArgument);">
  1. Include the xajax class library:
require_once("xajax.inc.php");
  1. Instantiate the xajax object:
$xajax = new xajax();
  1. Register the names of the PHP functions you want to be able to call through xajax:
$xajax->registerFunction("myFunction");
  1. Write the PHP functions you have registered and use the xajaxResponse object to return XML commands from them:
  2. function myFunction($arg)
  3. {
  4.   // do some stuff based on $arg like query data from a database and
  5.   // put it into a variable like $newContent
  6.   // Instantiate the xajaxResponse object
  7.   $objResponse = new xajaxResponse();
  8.   // add a command to the response to assign the innerHTML attribute of
  9.   // the element with id="SomeElementId" to whatever the new content is
  10.   $objResponse->addAssign("SomeElementId","innerHTML", $newContent);
  11.   //return the XML response generated by the xajaxResponse object
  12.   return $objResponse->getXML();
}
  1. Before your script sends any output, have xajax handle any requests:
$xajax->processRequests();
  1. Between your <head></head> tags, tell xajax to generate the necessary JavaScript:
<?php $xajax->printJavascript(); ?>
  1. Call the function from a JavaScript event or function in your application:
  2. <div id="SomeElementId"></div>
<button onclick="xajax_myFunction(SomeArgument);">
 
就这么简单. xajax 会处理其他所有的事情. 你所要做的主要工作就是编写PHP函数,然后从函数之中返回xajax的XML响应。而后者通过xajaxResponse类可以非常简单的生成.
That's it. xajax takes care of most everything else. Your biggest task is writing the PHP functions and returning xajax XML responses from them-- which is made extremely easy by the xajaxResponse class.
 
评论人 评论内容摘要(共 0 条,查看完整内容) 得分 0 发表时间
关于本站 | 广告服务 | 版权声明 | 联系我们 | | 联系我 | 交流群:1361692 7710545
本站部分带宽由:华夏名网武汉IDC数据中心 赞助[排名不分先后] Powered By 零度软件园
本站软件均来源于网络,仅供学习所用。若侵犯了你的权益,请立即通知我们,我们将第一时间删除!