ExtJS之Ext.Ajax.request用法详解.doc

上传人:壹****1 文档编号:561459164 上传时间:2023-12-18 格式:DOC 页数:9 大小:52.01KB
返回 下载 相关 举报
ExtJS之Ext.Ajax.request用法详解.doc_第1页
第1页 / 共9页
ExtJS之Ext.Ajax.request用法详解.doc_第2页
第2页 / 共9页
ExtJS之Ext.Ajax.request用法详解.doc_第3页
第3页 / 共9页
ExtJS之Ext.Ajax.request用法详解.doc_第4页
第4页 / 共9页
ExtJS之Ext.Ajax.request用法详解.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《ExtJS之Ext.Ajax.request用法详解.doc》由会员分享,可在线阅读,更多相关《ExtJS之Ext.Ajax.request用法详解.doc(9页珍藏版)》请在金锄头文库上搜索。

1、ExtJS之Ext.Ajax.request用法详解 Java代码 1 Ext.Ajax.request( 2 url:findbyid.action, 3 params: 4 id:cell.getId() 5 , 6 success: function(resp,opts) 7 var respText = Ext.util.JSON.decode(resp.responseText); 8 name=respText.name; 9 oid=respText.id; 10 findbyid(graph,cell,oid,name); 11 /Ext.Msg.alert(错误, respT

2、ext.name+=+respText.id); 12 , 13 failure: function(resp,opts) 14 var respText = Ext.util.JSON.decode(resp.responseText); 15 Ext.Msg.alert(错误, respText.error); 16 17 18 ); 在Ext开发过程中,基本上时刻需要用到异步请求,那么这个请求到底是怎么执行的呢,我们接下来来探讨下 首先:Ext.Ajax类继承了Ext.data.Connection,为Ajax的请求提供了最大灵活性的操作方式再简单请求基础上我们加上一个使用的 说明的是这

3、种请求通常都是放在触发某个事件的处理方法中的url:就是我们要请求的路径params:里面的参数用逗号隔开,就是我们要发出请求带的参数success:是服务器处理成功返回failure:是服务器处理失败返回重点讲的就是如何处理返回值信息,我们的resp这个参数就显得非常重要了resp是Ext构造的一个返回结果对象,如服务器端返回“this is a test!”(可以通过throw new Exception(this is a test!)简单实现)。那么返回将是如下内容:Java代码 19 tId.1 20 status.200 21 statusText.OK 22 getRespons

4、eHeader.object Object 23 getAllResponseHeaders.Server: Apache-Coyote/1.1 24 Content-Type: text/html;charset=GBK 25 Content-Language: zh-CN 26 Content-Length: 108 27 Date: Wed, 31 Oct 2007 12:51:23 GMT 28 responseText. 29 30 31 错误 32 33 34 错误:this is a test! 35 36 37 responseXML. 38 argument.undefine

5、d 从上面结果可以看出来,最开始是一些状态属性,我们也不常用,不管他。里面真正常用的是responseText与responseXML两个属性,那么这里面的responseText内容又被Ext用html包装了,但使用Ext.MessageBox展示出来正合适;reponseXML将在服务器端返回“text/xml”类型时使用。若服务器端返回是“text/json”类型时,客户端需要使用obj= Ext.util.JSON.decode(result.responseText);进行构造json对象,然后就可以正常使用了具体操作返回值 我们用JSON就这么写ServletActionConte

6、xt.getResponse().setContentType(text/json; charset=utf-8);ServletActionContext.getResponse().getWriter().write(success:true,info:更新信息成功,name: + oo.getName() + ,id: + id + );显然我这里返回的是JSON的值了(记住里面的属性值一定要加单引号) var respText = Ext.util.JSON.decode(resp.responseText); 这个就可获得返回结果对象,要使用属性的话respText.id等都可直接用

7、了说到这里如果还想对这里面其他配置感兴趣的话可以参考下面的语句url : String/Function (Optional)(可选项)发送请求的url,默认为配置的url。 若为函数类型那么其作用域将由配置项scope所指定。默认为配置好的URL。 The URL to which to send the request, or a function to call which returns a URL string. The scope of the function is specified by the scope option. Defaults to configured URL

8、.params : Object/String/Function (可选项)(Optional)一包含属性的对象(这些属性被用作request的参数)或一个编码后的url字串或一个能调用其中任一一属性的函数。 若为函数类型那么其作用域将由配置项scope所指定。 An object containing properties which are used as parameters to the request, a url encoded string or a function to call to get either. The scope of the function is spec

9、ified by the scope option.method : String (可选项)(Optional)该请求所用的http方面,默认值为配置的方法,或者当没有方法被配置时,如果没有发送参数时用get,有参数时用post。 The HTTP method to use for the request. Defaults to the configured method, or if no method was configured, GET if no parameters are being sent, and POST if parameters are being sent.

10、Note that the method name is case-sensitive and should be all caps.callback : Function (可选项)(Optional)该方法被调用时附上返回的http response对象。不管成功还是失败,该回调函数都将被调用,该函数中传入了如下参数: The function to be called upon receipt of the HTTP response. The callback is called regardless of success or failure and is passed the fo

11、llowing parameters:options : Object请求所调用的参数。The parameter to the request call.success : Boolean请求成功则为true。True if the request succeeded.response : Object包含了返回数据的xhr对象。The XMLHttpRequest object containing the response data. Seehttp:/www.w3.org/TR/XMLHttpRequest/ for details about accessing elements o

12、f the response.success: Function (可选项)(Optional)该函数被调用取决于请求是否成功。该回调函数被传入如下参数: The function to be called upon success of the request. The callback is passed the following parameters:response : Object包含数据的xhr对象。The XMLHttpRequest object containing the response data.options : Object请求所调用的参数。The paramet

13、er to the request call.failure : Function (可选项)(Optional)该函数被调用取决于请求失败。该回调函数被传入如下参数: The function to be called upon failure of the request. The callback is passed the following parameters:response : Object包含数据的xhr对象。 The XMLHttpRequest object containing the response data.options : Object请求所调用的参数。 The parameter to the request call.scope : Object (可选项)(Optional)回调函数的作用域:回调函数this对象指针。默认值为浏览器窗口。 The scope in which to execute the callbacks: The this object for the callback function. If the url, or params options were specified as functions from which to draw values, then this also serves as the s

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号