prototype1.4简介_yj
你需要完成AJAX逻辑的时候,这个包如何让它更容易。Ajax 对象是一个预定义对象,由这个包创建,为了封装和简化编写AJAX 功能涉及的狡猾的代码。 这个对象包含一系列的封装AJAX逻辑的类。我们来看看其中几个类
3.1 使用Ajax.Request类
如果你不使用任何的帮助程序包,你很可能编写了整个大量的代码来创建
XMLHttpRequest对象并且异步的跟踪它的进程, 然后解析出响应 然后处理它。当你不
需要支持多于一种类型的浏览器时你会感到非常的幸运。 为了支持 AJAX 功能。这个包定义了 Ajax.Request 类。
假如你有一个应用程序可以通过url http://yoursever/app/get_sales?empID=1234&year=1998与服务器通信。它返回下面这样的XML 响应。
<?xml version="1.0" encoding="utf-8" ?> <ajax-response>
<response type="object" id="productDetails"> <monthly-sales> <employee-sales>
<employee-id>1234</employee-id> <year-month>1998-01</year-month> <sales>$8,115.36</sales> </employee-sales> <employee-sales>
<employee-id>1234</employee-id> <year-month>1998-02</year-month> <sales>$11,147.51</sales> </employee-sales> </monthly-sales> </response> </ajax-response>
用 Ajax.Request对象和服务器通信并且得到这段 XML是非常简单的。下面的例子演示了它是如何完成的。
<script>
function searchSales(){
var empID=$F('lstEmployees'); var y=$F('lstYears');
var url='http://yoursever/app/get_sales'; var pars='empID='+empID+'&year='+y;
var myAjax=new Ajax.Request(url,{
method:'get',parameters:pars,onComplete:showResponse }); }
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库prototype1.4简介_yj(7)在线全文阅读。
相关推荐: