ExtJs 4.x Ajax简单封装
/*** Ajax 请求*/ Ext.define("SinoCloudAjaxRequestClass", {constructor : function () {var me = this;var viewport = me.getViewPort();if(viewport){window.sinoCloudAjaxRequestClassLoadingMak = new Ext.LoadMask(viewport, {msg:"处理中..."});}},request : function (method,param, url, func,anotherFunc) { //用于执行ajax请求,其中,func为第一个回调方法,一般用于执行成功提示,可以使用该类的commonPrompt,也可以直接处理成功请求后的业务,anotherFunc用于处理请求成功后执行的业务,可选var me = this;me.showViewportLoading();Ext.Ajax.request({url: url,params: param,method: method,success: function (response, options) {me.hideViewportLoading();if(func){func(response, options,anotherFunc);}else{Ext.Msg.alert('error', 'error...did not define ajax callback function...');}}, failure: function (response, options) {me.hideViewportLoading();Ext.Msg.alert('错误', '系统错误,请稍候再试!');}});},get: function (param, url, func,anotherFunc) {var me = this;me.request("get",param,url,func,anotherFunc);}, post: function (param, url, func,anotherFunc) {var me = this;me.request("post",param,url,func,anotherFunc);},commonPrompt : function (response, options,anotherFunc) { //一般提示if(anotherFunc){anotherFunc(response,options);}var text = response.responseText;if (text) {text = text.trim();var json = Ext.decode(text);var success = json.success;if (success) {Ext.Msg.alert('提示', "操作成功!");} else {var msg = json.msg;if(msg){Ext.Msg.alert('提示', msg);}else{Ext.Msg.alert('提示', "操作失败!");}}} else {Ext.Msg.alert('提示', "系统错误...");}},getViewPort : function () {return Ext.getBody();},showViewportLoading : function () {if(sinoCloudAjaxRequestClassLoadingMak){sinoCloudAjaxRequestClassLoadingMak.show();}},hideViewportLoading : function () {if(sinoCloudAjaxRequestClassLoadingMak){sinoCloudAjaxRequestClassLoadingMak.hide();}} });
使用方式 :
var ajax = Ext.create("SinoCloudAjaxRequestClass"); var param = {id : 1 }; var url = "demo.action";; ajax.post(param,url,function(response, options){});或者 : ajax.post(param,url,ajax.commonPrompt,function(response, options){});ajax.commonPrompt 会自动验证返回的json的success并给出提示
转载于:https://www.cnblogs.com/hythzx/p/4654415.html
ExtJs 4.x Ajax简单封装相关推荐
- ajax排行页面,ajax简单页面
简单的注册页面运用ajax 主页面 无标题文档 //首先引用jquery文件 登录页面 用户名: 密码: $("#btn").click(function(){ //1.取内容 v ...
- 用ExtJs+Linq+Wcf打造简单grid
本系列文章列表 1)Ajax访问Xml Web Service的安全问题以及解决方案 2)Ajax与WCF交互-WCF之美 3) Ajax与Wcf交互-JSON 4) ExtJs与WCF交互:生成树 ...
- ajax请求封装,封装的ajax请求
在做登录注册这类提交表单数据时,我们经常需要局部刷新网页来验证用户输入的信息,这就需要用到ajax请求,我们通常需要获取表单中的数据,发起ajax请求,通过服务程序,与数据库的数据进行比对,判断信息的 ...
- ajax 加载 提示 锁屏,js锁屏解屏通过对$.ajax进行封装实现
jquery插件源码: /** * 对jquery中$.ajax进行封装,以便加入锁屏功能 * isAsync 是否为异步请求,默认为true * isLock 是否锁屏,默认是true * isCa ...
- Android APP更新下载工具类——简单封装DownloadManager
几乎所有APP都包含了检查更新功能,更新下载功能的实现方式常用的有两种:1.使用App网络框架的文件下载请求:2.使用自带的DownloadManager类:本文介绍第二种,简单封装一下Downloa ...
- 简单封装浏览器 cookie 工具类
版权声明:本文首发 http://asing1elife.com ,转载请注明出处. https://blog.csdn.net/asing1elife/article/details/8265571 ...
- 小程序简单封装 request 请求
我在这里做了详细的介绍 : 小程序简单封装 request 请求 转载于:https://www.cnblogs.com/biangz/p/9984340.html
- 简单封装 HTTP 请求
2017-2-19 更新到第二版: 源码地址:http://git.oschina.net/sp42/ajaxjs/tree/master/ajaxjs-base/src/com/ajaxjs/net ...
- 【JDBC】实现对JDBC 连接的简单封装
package util;import java.sql.Connection; import java.sql.DriverManager;/**** 实现对JDBC 的封装* @author mq ...
最新文章
- 趣图:老手调试多线程,666
- api质量等级_第1150期 简单又易操作的辨别润滑油质量的方法
- php 克隆对象,php中对象的复制与克隆
- on the way
- 开源项目推荐ruoyi
- odoo 14 手册 客户 报价单 销售订单
- go语言反汇编linux,Go语言函数的底层实现
- 智能计算系统1 环境搭建
- MySQL 5.7详细下载安装配置教程
- 云片网短信服务使用Java
- Windows10系统桌面美化,定制自己的专属桌面.
- Domoticz-Dummy(虚拟传感器)
- Linux上svnserve “db/txn-current-lock: Permission denied“ 问题解决办法
- 【系统分析师】操作系统
- [c语言]c语言中的#和##作用、参数表省略号作用
- 计算机组成原理课后答案(唐朔飞第二版)
- CS0533隐藏继承的抽条成员/CS0534不实现继承的抽象成员
- \t \n \n\t在python中的用法
- 服务降级(服务回退)
- mysql中vlookup函数_excel精确匹配vlookup用法(数据库属性匹配)