ExtJS之Ext.Ajax.request用法详解
在Ext开发过程中,基本上时刻需要用到异步请求,那么这个请求到底是怎么执行的呢,我们接下来来探讨下
首先:Ext.Ajax类继承了Ext.data.Connection,为Ajax的请求提供了最大灵活性的操作方式
再简单请求基础上我们加上一个使用的
Ext.Ajax.request({
url:'findbyid.action',
params:{
id:cell.getId()
},
success: function(resp,opts) {
var respText = Ext.util.JSON.decode(resp.responseText);
name=respText.name;
oid=respText.id;
findbyid(graph,cell,oid,name);
//Ext.Msg.alert('错误', respText.name+"====="+respText.id);
},
failure: function(resp,opts) {
var respText = Ext.util.JSON.decode(resp.responseText);
Ext.Msg.alert('错误', respText.error);
}
});
说明的是这种请求通常都是放在触发某个事件的处理方法中的
url:就是我们要请求的路径
params:里面的参数用逗号隔开,就是我们要发出请求带的参数
success:是服务器处理成功返回
failure:是服务器处理失败返回
重点讲的就是如何处理返回值信息,我们的resp这个参数就显得非常重要了
resp是Ext构造的一个返回结果对象,如服务器端返回“this is a test!”(可以通过throw new Exception("this is a test!")简单实现)。那么返回将是
如下内容:
tId.1
status.200
statusText.OK
getResponseHeader.[object Object]
getAllResponseHeaders.Server: Apache-Coyote/1.1
Content-Type: text/html;charset=GBK
Content-Language: zh-CN
Content-Length: 108
Date: Wed, 31 Oct 2007 12:51:23 GMT
responseText.
<html>
<head>
<title>错误</title>
</head>
<body>
<h1>错误:this is a test!</h1>
</body>
</html>
responseXML.
argument.undefined
从上面结果可以看出来,最开始是一些状态属性,我们也不常用,不管他。里面真正常用的是responseText与responseXML两个属性,那么这里面的responseText内容又被Ext用html包装了,但使用Ext.MessageBox展示出来正合适;reponseXML将在服务器端返回“text/xml”类型时使用。若服务器端返回是“text/json”类型时,客户端需要使用obj= Ext.util.JSON.decode(result.responseText);进行构造json对象,然后就可以正常使用了
具体操作返回值 我们用JSON就这么写
ServletActionContext.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等都可直接用了
说到这里如果还想对这里面其他配置感兴趣的话可以参考下面的语句
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.
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 specified 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. 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 following 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. See http://www.w3.org/TR/XMLHttpRequest/ for details about accessing elements of 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 parameter 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 scope for those function calls. Defaults to the browser window.
form : Element/HTMLElement/String (可选项)(Optional)
用来压入参数的一个 <form>元素或 <form>的标识。 The <form> Element or the id of the <form> to pull parameters from.
isUpload : Boolean (可选项)(Optional)
如果该form对象是上传form,为true(通常情况下会自动探测)
headers : Object (可选项)(Optional)
为请求所加的请求头。 Request headers to set for the request.
xmlData : Object (可选项)(Optional)
用于发送的xml document。注意:它将会被用来在发送数据中代替参数任务参数将会被追加在url中。 XML document to use for the post. Note: This will be used instead of params for the post data. Any params will be appended to the URL.
jsonData : Object/String (可选项)(Optional)
JSON data to use as the post. Note: This will be used instead of params for the post data. Any params will be appended to the URL.
disableCaching : Boolean (可选项)(Optional)
设置为True,则添加一个独一无二的cache-buster参数来获取请求。 True to add a unique cache-buster param to GET requests
分享到:
相关推荐
1.程序功能说明: MATLAB实现多种群遗传算法(完整代码) 逼近C=[9,8,7,6,5,4,3,2,1]的9维向量. 2.代码说明:注释清晰,参数和变量说明清晰,方便更改、方便初学者使用,模块化编程,方便替换目标函数。运行环境Windows7及以上操作系统,MATLAB2014a及以上版本。 3.适用专业:计算机、电子信息工程、数学、物理、机械工程、土木工程等专业的大学生、研究生毕业设计,各类专业的课程设计、海外留学生作业等。 4作者介绍:资深算法工程师, 从事Matlab、Python算法仿真工作15年,专业研究遗传算法、粒子群算法、蚁群算法、鲸鱼算法、狼群算法等. 有问题联系QQ: 1579325979
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
免费JAVA毕业设计 2024成品源码+论文+录屏+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
小学元旦晚会PPT 模版
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
MATLAB中的语义分割技术探究与应用实践,matlab,语义分割 ,matlab; 语义分割,Matlab语义分割技术解析
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
1、文件内容:pulseaudio-10.0-6.el7_9.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/pulseaudio-10.0-6.el7_9.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、安装指导:私信博主,全程指导安装
"基于OpenCV与深度学习的人脸表情识别系统:利用Python与PyQt构建的可视化实时检测工具",基于OpenCV的人脸表情识别系统 相关技术:python,opencv,pyqt,深度学习 (请自行安装向日葵远程软件,以便提供远程帮助) 可编译为.exe文件。 软件说明:摄像头实时检测,加载照片,视频均可。 有基础的同学,可自行修改完善。 第一张和第二张为运行截图。 ,基于OpenCV的人脸表情识别系统; Python; OpenCV; PyQt; 深度学习; 实时检测; 照片和视频支持; 可编译为.exe文件; 运行截图。,"基于OpenCV与深度学习的人脸表情识别系统"
,步进方案,步进源码,两相步进矢量控制,超前角控制两种模式,成熟产品方案 支持特殊功能定制
三相储能PCS双向能量流动与Matlab仿真控制研究——基于SVPWM调制技术的建模与应用,三相储能PCS(Matlab仿真) 1.可实现Grid to Battery,Battery to Grid的能量双向流动。 2.本仿真基于Matlab仿真建立的模型, 3.采用SVPWM进行控制 ,三相储能PCS; 双向能量流动; Matlab仿真; SVPWM控制,三相储能PCS:能量双向流Matlab仿真模型(SVPWM控制)
deepseek部署教程.md
nodejs010-nodejs-ansicolors-0.3.2-1.el6.centos.alt.noarch.rpm
基于三菱PLC的四路抢答器控制系统原理及实践:含带解释的梯形图与IO分配图解,三菱 MCGS 基于PLC的四路抢答器控制系统 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,三菱MCGS; PLC四路抢答器; 控制系统; 梯形图接线图; 原理图图纸; IO分配; 组态画面。,三菱PLC四路抢答器控制系统原理图及组态画面解析
基于运动数据时空特征提取的人类运动片段.pdf
基于机器学习的选股模型及投资组合研究.pdf
ollama安装包。。。。。。。。。。。。。。。。。
nodejs010-nodejs-ansistyles-0.1.3-1.el6.centos.alt.x86_64.rpm
Screenshot_20250201_111207_com_tencent_mm_LauncherUI.jpg
基于时空Transformer的端到端的视频注视目标检测.pdf