您的位置: 首页 > 技术文档 > 网络编程 > 十分钟学会 xajax
网站(B/S开发中)cache应用 回到列表 URL重写实现IHttpHandler接口
 十分钟学会 xajax

作者:alphat 时间: 2006-06-23 文档类型:翻译 来自:蓝色理想

第 1 页 十分钟学会 xajax [1]
第 2 页 十分钟学会 xajax [2]

call the function from a javascript event or function in your application:
从你程序中的js 事件或函数调用之前你已经注册过的相对应函数

<div id="someelementid"></div>
<button onclick="xajax_myfunction(someargument);">

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.
只需这些步骤。其他的交由xajax 去处理吧。你最主要的任务只是编写php中的函数,只要使它们能返回xajax的xml响应就行了,而这步可以用xajaxresponse 类轻松解决。

how do i update my content asynchronously?
如何异步更新我的内容?

perhaps the most unique feature of xajax is the xajaxresponse class. other ajax libraries require you to write your own callback handlers in javascript to process the data returned from an asynchronous request and to update the content. xajax, on the other hand, allows you to easily control your content from php. the xajaxresponse class allows you to create xml instructions to return to your application from your php functions. the xml is parsed by xajax message pump and the instructions tell xajax how to update the content and state of your application. the xajaxresponse class currently offers a number of useful commands, such as assign, which sets the specified attribute of an element in your page; append, which appends data to the end of the specified attribute of an element in your page; prepend, which prepends data to the beginning of the specified attribute of an element in your page; replace, which searches for and replaces data in the specified attribute of an element in your page; script, which runs the supplied javascript code; and alert, which shows an alert box with the supplied message text.
xajax最独特的长处也许就是 xajaxresponse class了。其它的ajax库需要你亲自写用js写回调的句柄,来处理一个异步请求而且得到的数据,并更新其内容。另一方面,xajax只需你简单的控制好php的内容。然后通过xajaxresponse 类,使在你的php函数中创建xml指令返回给你的程序。xml将被 xajax的信息(pump)解析。其指令告知xajax将如何更新内容和你程序中的位置。现在xajaxresponse 已经提供了大量并有帮助的指令:http://www.flaspx.com/weblog/blog.php?bid=16  (略...付上详细的xajaxresponse 类说明)

a single xml response may contain multiple commands, which will be executed in the order they were added to the response. for example, let's say that a user clicks on a button in your application. the onclick event calls the javascript wrapper for a php function. that wrapper sends an asynchronous request to the server through xmlhttprequest where xajax calls the php function. the php function does a database lookup, some data manipulation, or serialization. you use the xajaxresponse class to generate an xajax xml response containing multiple commands to send back to the xajax message pump to be executed:
一个单独xml响应可以包含多条命令,他们将依据加入响应的顺序来被执行。举个例子吧,让我们假设一个用户在你的程序中按下了一个按钮。这个按下的事件将调用被js封装好的php函数。这个封包通过 xmlhttprequest 发出了一个异步请求给服务器,让xajax调用php函数。这个php函数做了一个查询数据库,一些数据处理或排序的操作。而你要用 xajaxresponse 类来产出一个 xajax 的xml响应,它包含了多条命令。送给xajax 信息pump来执行:

$objresponse = new xajaxresponse();

$objresponse->addassign("myinput1","value",$datafromdatabase);
$objresponse->addassign("myinput1","style.color","red");
$objresponse->addappend("mydiv1","innerhtml",$datafromdatabase2);
$objresponse->addprepend("mydiv2","innerhtml",$datafromdatabase3);
$objresponse->addreplace("mydiv3","innerhtml","xajax","<strong>xajax</strong>");
$objresponse->addscript("var x = prompt(\"enter your name\");");

return $objresponse->getxml();

the xajax message pump would parse the xml message and perform the following:
xajax信息pump将会解析下列xml信息,并执行以下操作:

the value of the element with id myinput1 would be assigned to the data in $datafromdatabase.
将变量$datafromdatabase赋值给id为myinput1的value元素。

the color of the text in the element with id myinput1 would be changed to red.
id为myinput1的字体颜色元素将被换成红色.

the data in $datafromdatabase2 would be appended to the innerhtml of the element with id mydiv1.
$datafromdatabase2,此数据将被追加到id为mydiv1的innerthml元素的结束部位

the data in $datafromdatabase3 would be prepended to the innerhtml of the element with id mydiv2.
$datafromdatabase3,此数据将被添加到id为mydiv2的innerthml元素的开始部位

all occurrences of "xajax" in the innerhtml of the element with id mydiv3 would be replaced with "xajax"; making all of the instances of the word xajax appear bold.
id为mydiv3的innerhtml元素中所有的 "xajax" 将被替换成 "xajax",使所有的xajax以粗体显示。

a prompt would be displayed asking for the user's name and the value returned from the prompt would be placed into a javascript variable named x.
会有一个输入框弹出,并询问用户姓名。从输入框取得的变量将转换成js变量并命名为x。
all of this is implemented on the server side in the php function by forming and returning an xajax xml response.
所有这些组成了php函数在服务器端被执行,然后传回一个xml响应。

出处:蓝色理想
责任编辑:moby

上一页 十分钟学会 xajax [1] 下一页

◎进入论坛网络编程版块参加讨论

关键字搜索 常规搜索 推荐文档
热门搜索:CSS Fireworks 设计比赛 网页制作 web标准 用户体验 UE photoshop Dreamweaver Studio8 Flash 手绘 CG
站点最新 站点最新列表
周大福“敬•自然”设计大赛开启
国际体验设计大会7月将在京举行
中国国防科技信息中心标志征集
云计算如何让安全问题可控
云计算是多数企业唯一拥抱互联网的机会
阿里行云
云手机年终巨献,送礼标配299起
阿里巴巴CTO王坚的"云和互联网观"
1499元买真八核 云OS双蛋大促
首届COCO桌面手机主题设计大赛
栏目最新 栏目最新列表
浅谈JavaScript编程语言的编码规范
如何在illustrator中绘制台历
Ps简单绘制一个可爱的铅笔图标
数据同步算法研究
用ps作简单的作品展示页面
CSS定位机制之一:普通流
25个最佳最闪亮的Eclipse开发项目
Illustrator中制作针线缝制文字效果
Photoshop制作印刷凹凸字体
VS2010中创建自定义SQL Rule
>> 分页 首页 前页 后页 尾页 页次:2/21个记录/页 转到 页 共2个记录

蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。

转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。

特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有,文章若有侵犯作者版权,请与我们联系,我们将立即删除修改。

您的评论
用户名:  口令:
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以注册 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
不评分 1 2 3 4 5
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:
·不良评论请用报告管理员,以利管理员及时删除。
·尊重网上道德,遵守中华人民共和国的各项有关法律法规
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
·本站评论管理人员有权保留或删除其管辖评论中的任意内容
·您在本站发表的作品,本站有权在网站内转载或引用
·参与本评论即表明您已经阅读并接受上述条款
推荐文档 | 打印文档 | 评论文档 | 报告错误  
专业书推荐 更多内容
网站可用性测试及优化指南
《写给大家看的色彩书1》
《跟我去香港》
众妙之门—网站UI 设计之道
《Flex 4.0 RIA开发宝典》
《赢在设计》
犀利开发—jQuery内核详解与实践
作品集 更多内容

杂⑦杂⑧ Gold NORMANA V2