教你快速学会 xajax

彻骨的承诺

彻骨的承诺

2016-02-19 20:05

下面图老师小编要向大家介绍下教你快速学会 xajax,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!

译者按: xajax 最大的特点是他采用了xml response,这样我们可以用php来布置,处理异步传送数据之后,网页内容的更新。而这些操作其它的ajax 框架都是由js来完成的的。xajax 使我们只需要写一些php函数,就可以实现。

  所有学好xajax的关健在于熟练掌握 xajaxresponse 类。

  tutorials:learn xajax in 10 minutes

  教程:十分钟学会 xajax

  using xajax in a php script

  一个使用的xajax的php脚本:

  include the xajax class library:

  调用xajax类库:

  require_once("xajax.inc.php");

  instantiate the xajax object:

  实例化xajax对象

  $xajax = new xajax();

  register the names of the php functions you want to be able to call through xajax:

  注册一个你想用xajax来调用的php函数名(与javascript中的函数名相对应 xajax_myfunction)

  $xajax-registerfunction("myfunction");

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)

  write the php functions you have registered and use the xajaxresponse object to return xml commands from them:

  编写那个你刚刚已经注册的php函数,并从中用 xajaxresponse 对象来返回xml指令集

function myfunction($arg)
{
  // do some stuff based on $arg like query data from a database and
  // put it into a variable like $newcontent
  //对参数$arg做一些诸如:从数据库中获取数据后定义给$newcontent 变量的基本操作
  
  // instantiate the xajaxresponse object
  //实例化 xajaxresponse 对象
  $objresponse = new xajaxresponse();
  
  // add a command to the response to assign the innerhtml attribute of
  // the element with id="someelementid" to whatever the new content is
  // 在响应实例中添加一个命令,用来将id为someelementid的innerhtml元素属性
  // 变为任何新的内容.
  $objresponse-addassign("someelementid","innerhtml", $newcontent);
  
  //return the xml response generated by the xajaxresponse object
  //返回由 xajaxresponse 对象所生成的xml 响应
  return $objresponse-getxml();
}

  before your script sends any output, have xajax handle any requests:

  在你脚本传送出任何东西前,xajax都要处理所有请求

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)

  $xajax-processrequests();

  between your head/head tags, tell xajax to generate the necessary javascript:

  在该页的head和/head标签之间插入下列代码,使xajax实例可以自己生成所必需的js

  ?php $xajax-printjavascript(); ?

展开更多 50%)
分享

猜你喜欢

教你快速学会 xajax

Web开发
教你快速学会 xajax

十分钟学会 xajax

Web开发
十分钟学会 xajax

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

三招教你快速学会拍雪景

摄影 人像摄影 静物摄影
三招教你快速学会拍雪景

教你快速学会使用windows8系统

电脑入门
教你快速学会使用windows8系统

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

教你快速学会画平行眉:眉部肌肤如何护理?

画眉 彩妆 化妆
教你快速学会画平行眉:眉部肌肤如何护理?

教你学会如何看照片

摄影 人像摄影 静物摄影
教你学会如何看照片

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Java中数据库事务处理的实现

Java中数据库事务处理的实现

SPRING数据访问对象(DAO)框架入门

SPRING数据访问对象(DAO)框架入门
下拉加载更多内容 ↓