PHP之xAjax参考手册

什么是xajax?
xajax如何工作?
为什么我要使用xajax代替其他PHP的Ajax库?
如何在我的PHP脚本之中使用xajax?
如何异步更新内容?
如何异步处理表单数据?
如何给xajax增加定制功能?
我能在私有或者收费产品之中使用xajax吗?

什么是xajax?
Xajax是一个开源的 PHP 类库 它能够让你黏合HTML、CSS、JavaScript和PHP,轻而易举的开发功能强大、基于WEB的AJAX应用软件. 使用xajax开发的应用软件,无需重新调入页面,就能够异步调用服务器端的PHP函数和更新内容.

xajax 如何工作?
你的应用软件需要异步调用的PHP函数, xajax的PHP对象都生成了对应的封装好了的JavaScript函数. 当被调用时,封装的函数使用JavaScript的XMLHttpRequest对象与服务器异步通讯,调用xajax对象对应的PHP函数. 调用结束后, PHP函数由xajax返回一个xajax的XML响应传递给应用程序. XML响应包含了特定的指令和数据,他们可以被xajax的JavaScript消息分析器解析,并且被用于更新你的应用程序的内容.

为什么我要使用xajax代替其他PHP的ajax库?
你应该选择一个最是和你的项目需要的库.
xajax 提供了以下的功能, 它们使得ajax富有特色而又功能强大:

Xajax特殊的 XML 响应 / javascript 消息分析系统 帮助你做到, 自动的处理函数返回的数据,按照PHP函数返回的指令更新内容或者状态. 因为xajax作了这些工作Because xajax does the work, 你不需要写javascript的回调处理函数.

Xajax反对将代码和数据紧密地杂糅在一起的主张, 并且保持xajax的代码从与他代码分离. 因为它是对象构造的, 你可以加上自己定制的功能给xajax去扩展xajaxResponse 类和使用addScript方法.

xajax 可以工作在 Firefox, Mozilla, 大部分基于 Mozilla 的浏览器, Internet Explorer, 和 Safari.

除了更新元素的值和内含的HTML内容(innerHTML), xajax 还能用于更新样式(styles), css 类, 多选和单选按钮选择,甚至可以更新任何元素的属性.

xajax 支持使用一维或者多维数组、关联数组(哈希数组) 作为xajax函数的参数从javascript传送给PHP. 反之Additionally, 如果你传送一个javascript的对象给xajax函数,PHP函数将接受一个描叙对象属性的关联数组(哈希数组).

xajax 提供了一种简单的异步表单处理方式. 使用 xajax.getFormValues() javascript 方法, 你可以轻而易举的在表单之中提交一个描绘值的数组作为参数传送到xajax异步处理函数:
xajax_processForm(xajax.getFormValues(‘formId’);
. 它可以处理复杂的input 元素名称 ,例如 “checkbox[][]” 或者 “name[first]” 产生的多维或者关联数组(哈希数组), 就是普通提交表单那样使用PHP的$_GET数组

使用xajax你可以动态的发送附加的javascript作为请求的响应到你的应用软件中运行,而这就和动态的更新元素的属性一样方便.

Xajax会自动比较PHP函数返回的数据与你已经标记需要修改的元素属性. 只有当新的数据确实可以改变现有的属性,属性才会真的被更新. 这将可消除程序在一定时间间隔内更新与当前内容相同或者不同的内容而出现的明显的闪烁.

每一个通过xajax简单注册的函数都可以有不同的请求方式. 所有的函数默认使用POST方式,除非你明确的指定使用GET方式. 如果使用GET请求,你必须非常明确的考虑它确实是你所需要的

如果没有指定URI,xajax将设法自动确定脚本的URI. Xajax的自动确定算法经过了充分的验证,确保在大部分HTTPS或者未知端口的HTTP服务器上也可以正常的工作.

Xajax使用UTF8编码所有的请求和响应,以确保支持绝大部分的字符和语言. Xajax已经成功测试了多种不同的UNICODE字符,包括Spanish, Russian, Arabic, and Hebrew

几乎所有xajax生成的javascript都可以通过动态的外部javascript包含到你的web程序之中. 当你在浏览器之中查看程序的源代码时,不会有JavaScript的函数定义混杂在HTML标记之中.

Xajax可以使用在Smarty模板系统之中,仅仅需要创建一个smarty变量就可以包含xajax的javascript:
[coolcode linenum=”off” lang=”php”]
$smarty->assign(‘xajax_javascript’, $xajax->getJavascript());
[/coolcode]
然后你可以使用在header模版之中使用
[coolcode linenum=”off” lang=”php”]
{$xajax_javascript}
[/coolcode]
从而把xajax应用到你的站点.

如何在我的PHP脚本之中使用xajax?
Xajax的设计是如此的富有特色,以至于不管是已有的web程序还是新的项目,它都能够被极其简单的部署和应用. 仅仅需要七步,你就可以在几乎任何PHP脚本之中加入xajax的强大功能:

包含xajax类库:
[coolcode linenum=”off” lang=”php”]
require_once(“xajax.inc.php”);
[/coolcode]
实例化xajax 对象:
[coolcode linenum=”off” lang=”php”]
$xajax = new xajax();
[/coolcode]
注册你需要通过xajax调用的PHP函数的名称:
[coolcode linenum=”off” lang=”php”]
$xajax->registerFunction(“myFunction”);
[/coolcode]
编写注册的PHP函数,并且在函数之中使用xajaxResponse 对象返回XML指令:
[coolcode linenum=”off” lang=”php”]
function myFunction($arg)
{
// 对$arg做一些基本处理例如从数据库检索数据
// 然后把结果赋值给变量,例如$newContent

// 实例化xajaxResponse 对象
$objResponse = new xajaxResponse();

// 添加指令到响应之中,用于指派
//指定元素(例如id=”SomeElementId”)的innerHTML属性的新的内容
$objResponse->addAssign(“SomeElementId”,”innerHTML”, $newContent);

//返回xajaxResponse 对象生成的XML响应
return $objResponse->getXML();
}
[/coolcode]
在你的脚本输出任何信息之前,调用xajax用于接管请求:
[coolcode linenum=”off” lang=”php”]
$xajax->processRequests();
[/coolcode]
在页面的 标签之间, 告诉xajax生成所必需的JavaScript:
[coolcode linenum=”off” lang=”php”]
printJavascript(); ?>
[/coolcode]
在程序中,从JavaScript事件或者函数调用前面注册的函数:
[coolcode linenum=”off” lang=”php”]

0 thoughts on “PHP之xAjax参考手册”

  1. Wonderful beat ! I wish to apprentice even as you amend your website,
    how could i subscribe for a blog website?
    The account aided me a appropriate deal. I were a little bit acquainted of this your broadcast offered vivid clear concept

  2. I was extremely pleased to discover this site. I need to to thank you for ones time for this particularly fantastic read!!
    I definitely loved every little bit of it and I have
    you saved as a favorite to see new things on your site.

  3. Hiya very nice site!! Guy .. Beautiful .. Superb .. I’ll
    bookmark your blog and take the feeds additionally? I’m satisfied to seek out numerous
    helpful info here within the post, we need work out more techniques in this
    regard, thank you for sharing. . . . . .

  4. Excellent blog you have here but I was wondering if
    you knew of any community forums that cover the same topics discussed in this article?

    I’d really love to be a part of group where I can get feed-back from other knowledgeable people that share the same interest.
    If you have any suggestions, please let me know. Kudos!

  5. Definitely consider that that you stated. Your favourite justification seemed to be at the web the easiest thing to keep in mind of.
    I say to you, I certainly get irked even as other people
    consider worries that they just do not know about. You controlled to hit the
    nail upon the highest and also outlined out the entire thing without having side effect , other people can take a signal.
    Will probably be again to get more. Thank you

  6. Hmm it looks like your website ate my first comment (it was super long) so I guess I’ll
    just sum it up what I had written and say, I’m thoroughly
    enjoying your blog. I as well am an aspiring blog writer but I’m still new to the whole thing.
    Do you have any tips for rookie blog writers? I’d certainly
    appreciate it.

  7. Awesome blog! Is your theme custom made or did
    you download it from somewhere? A theme like yours with a few simple tweeks would really make
    my blog shine. Please let me know where you got your theme.
    Thanks a lot

  8. What i do not realize is in fact how you’re no longer actually a lot more smartly-preferred than you may be now.
    You’re very intelligent. You realize therefore significantly relating
    to this topic, made me personally consider it from a lot
    of varied angles. Its like women and men aren’t fascinated unless it is one thing
    to do with Girl gaga! Your individual stuffs nice. At all times
    care for it up!

  9. Hi there, just became alert to your blog through Google,
    and found that it’s truly informative. I’m gonna watch out for
    brussels. I’ll be grateful if you continue this in future.
    Numerous people will be benefited from your writing.
    Cheers!

  10. Hello I am so excited I found your web site, I really
    found you by error, while I was looking on Yahoo for something else, Nonetheless I am here now and would just like
    to say thank you for a marvelous post and a all round exciting blog (I also love the
    theme/design), I don’t have time to go through it all at the minute but I have bookmarked it and
    also added your RSS feeds, so when I have time I will be
    back to read a great deal more, Please do keep up the superb job.

  11. I loved as much as you’ll receive carried out right here.
    The sketch is attractive, your authored material stylish.
    nonetheless, you command get bought an impatience over that you wish be delivering the following.
    unwell unquestionably come more formerly again since exactly the
    same nearly a lot often inside case you shield this hike.

  12. Scientists consider that the sale of tree seeds shall grow to be an additional source of incomes for local peasants,
    and lovers of gardening from all around the world shall have the opportunity to plant the enormous self-destructing palm tree by themselves.
    For those who should not have a huge garden or outdoor area then you can buy
    miniature palm trees. WA green and clean backyard area in any residential
    or commercial house definitely adds as much as the overall aesthetics.
    The feeling of getting food served in such places may be very
    high because it offers inexperienced and natural look.
    Also these provide pure green look and anyone
    utilizing such plates of bowl feel good to be served in such a naturally made dinnerwares.
    Palm Leaf Plates or Bio plates are made from the shedded leaves of the Palm Tree.
    No timber are chopped or lower at any stage through
    the making process and only shedded palm leaves
    are used to make this product. Soaking up comfortable-filtered sunlight underneath the shed of
    palm trees offers final pleasure, making you are feeling as if being within the
    lap of nature. Remember that in case you plan a tropical setting occasion these timber will really make your friends feel relax.

  13. Tired of endless aggression often here Seems
    social media is dividing just now Something tranquil An almost
    subtropic illusion TW1 In feel – not fact Ensete Cycas Washingtonia filifera Phoenix canariensis Butia capitata Trachycarpus fortunei Musa basjoo Big drifts Echium pininana

  14. When I originally commented I clicked the “Notify me when new comments are added” checkbox
    and now each time a comment is added I get three e-mails with the same comment.

    Is there any way you can remove people from that service?
    Bless you!

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image