【翻译】Ext JS 4——Ajax和Rest代理处理服务器端一场和消息的方法
原文:EXTJS4 - Handle Server-side exceptions and message from an Ajax or Rest proxy
作者:Raja
可能要处理的情况:
success(成功)——Ext处理
failure(失败),由于通讯问题——Ext处理
failure(失败),由于服务器端异常——开发人员人员必须处理的响应失败……
解决方案一:
在应用程序控制器中编写以下方法:
//Ajax Response Error HandlerExt.Ajax.on('requestexception', function(conn, response, options, eOpts) {var error = response.status + ' - ' + response.statusText;console.log('Ajax Request Exception! '+error);if (response.status != 200) {
var errorData = Ext.JSON.decode(response.responseText); console.log('ajax req error:'+errorData.message);console.log('Ajax request Error', response.status);}});
解决方案二:
当在服务器端发生异常时,可以将500作为响应标头,原因作为HTML内容发送回客户端。
store.on('loadexception',
function(a,conn,resp) {
if (resp.status == '304') {Ext.Msg.alert('Content has not changed');
}else if(resp.status == '200') {
return; //Do nothing
}else if (resp.status == '401') {Ext.Msg.alert('Authentication required - You need to Login');
}else if (resp.status == '302') {
errorDialog.body.update('Session Has Expired');
errorDialog.show();
}else if(resp.status == '500') {
errorDialog.body.update(resp.responseText);
errorDialog.show();
}else{
errorDialog.body.update('An uncaught exception has occured');
errorDialog.show();
}
}
解决方案三:
当发送Ajax或REST请求时,Ext JS 4代理通常会预期返回的信息包括参数:data、success和message。参数message是可选的,不过当需要将请求结果显示给用户的时候,它就可派上用场了。
function requestMessageProcessor(proxy, response) {if (response && proxy) { try { var responseData = proxy.reader.getResponseData(response);if (responseData.message) {var messageDescription = 'Information'; // title of the alert boxvar messageIcon = Ext.MessageBox.INFO;if (!responseData.success){var messageDescription = 'Error';var messageIcon = Ext.MessageBox.ERROR;}Ext.MessageBox.show({title: messageDescription,msg: responseData.message,buttons: Ext.MessageBox.OK,icon: messageIcon});}}catch(err) {// Malformed response most likelyconsole.log(err);}}
}
And here’s the part which should reside in proxy:proxy: {...listeners: { exception: function(proxy, response, options) {requestMessageProcessor(proxy, response);}},afterRequest: function(request, success) {requestMessageProcessor(request.scope, request.operation.response);}
}
转载于:https://www.cnblogs.com/hainange/p/6334159.html
【翻译】Ext JS 4——Ajax和Rest代理处理服务器端一场和消息的方法相关推荐
- 翻译 - EXT JS 5:Controlling an Application with Router
最近做管理后台苦于前端样式,遂想学习在Ext,继而从新发布的5下手,英语水平有限,且翻且纠结着,欢迎指正. 原文:http://docs.sencha.com/extjs/5.0.0/applicat ...
- 流行的AJAX框架对比:jQuery,Mootools,Dojo,Ext JS
来源:http://developer.51cto.com/art/200906/129502.htm 本文介绍了四种流行的AJAX框架,包括简洁的jQuery,面向对象的 Mootools,拥有强大 ...
- 【翻译】Ext JS最新技巧——2015-8-11
原文:Top Support Tips Seth Lemmons:使用棒极了的Awesome Font Ext JS 6附带了一个新的海卫一主题,可以使用Font Awesome字体作为背景图像的图标 ...
- ext get id js_【翻译】Ext JS最新技巧——2015-8-11
Seth Lemmons:使用棒极了的Awesome Font Ext JS 6附带了一个新的海卫一主题,可以使用Font Awesome字体作为背景图像的图标.不过,你知道如何通过"ico ...
- [导入]几种流行的AJAX框架jQuery,Mootools,Dojo,Ext JS的对比
AJAX是web20的基石,现在网上流行几种开源的AJAX框架,比如:jQuery,Mootools,Dojo,Ext JS等等,那么我们到底在什么情况下该使用那个框架?以下是一组摘抄的数据: Aja ...
- 【翻译】Ext JS 4.2介绍
原文:Introducing Ext JS 4.2 Ext JS 4.2包含了许多令人兴奋的增强功能和特性.你可能已经在之前的文章中阅读过相关的一些功能和特性了,如Grid组件改进.在这篇文章中,将介 ...
- extjs ajax 遮罩层,[Ext JS 4] 实战之Load Mask(加载遮罩)的显示与隐藏
前言 Load Mask(遮罩)效果,就是在页面还没有完全显示出来之前, 加上一个转装转的效果. 类似: 添加这样的效果有两个好处: 1. 在页面没完全show出来之前, 把后面的页面给遮罩起来, 防 ...
- Sencha Cmd 6 和 Ext JS 6 指南文档(部分官方文档中文翻译)
近期组织了几个程序员网友,正在翻译一部分官方的Sencha Cmd 6 和 Ext JS 6 指南文档. 眼下还没翻译完,大家能够先看看 Sencha Cmd 6 和 Ext JS 6 指南文档 ( ...
- 【翻译】Ext JS——高效的编码风格指南
原文:ExtJS - Efficient coding style guide 作者:Raja 切勿使用"new"关键字:在Ext JS中,使用"new"关键字 ...
最新文章
- python bar
- [Linux]history 显示命令执行的时间
- SQLite学习手册(数据表和视图)
- Sublime 解决目录显示为方块的问题
- 【HTML/CSS】CSS盒模型及其理解
- 服务器响应401,服务器返回HTTP响应代码:401,URL:https
- 媒体查询Media Queries详解
- Bootstrap系列 -- 44. 分页导航
- Linux VIM编辑器详解
- 钝化 会钝化 订单审批流程 码一会er
- 《达芬奇密码》读后感
- 普及练习场 深度优先搜索 八皇后
- git 某个分支直接覆盖当前master分支
- DiskGenius备份/还原分区=备份Windows系统
- 在VMware上如何创建虚拟机以及安装Linux操作系统
- 历次重要底部的数据特征 A股或将继续下跌?
- Parallel Platform (Stewart Platform) 类型机械臂的正逆解 01
- usbview 源码结构分析
- 硅晶圆出货量大涨带好消息:电脑手机数码产品价格暂时平稳
- nodejs的部署的问题