Js代码
- //异步ajax调用
- /**
- * 异步调用ajax,成功后返回值,作为回调函数的参数 调用失败会提示
- *
- * @param {}
- * urlStr
- * @param {}
- * paramsObj
- * @param {}
- * callbackFunc
- */
- function ajaxCall(urlStr, paramsObj, callbackFunc) {
- Ext.Ajax.request({
- url : urlStr,
- params : paramsObj,
- method : 'POST',
- success : function(response) {
- if (callbackFunc) {
- var result = Ext.util.JSON
- .decode(response.responseText);
- var cbfn = callbackFunc.createCallback(result);
- cbfn();
- }
- },
- failure : function() {
- Ext.Msg.alert("提示", "方法调用失败");
- }
- });
- }
- //同步ajax调用
- /**
- * 同步ajax调用 返回json Object
- *
- * @param {}
- * urlStr
- * @param {}
- * paramsStr 为字符串键值对形式“key=value&key2=value2”
- * @return {} 返回json Object
- */
- function ajaxSyncCall(urlStr, paramsStr) {
- var obj;
- var value;
- if (window.ActiveXObject) {
- obj = new ActiveXObject('Microsoft.XMLHTTP');
- } else if (window.XMLHttpRequest) {
- obj = new XMLHttpRequest();
- }
- obj.open('POST', urlStr, false);
- obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- obj.send(paramsStr);
- var result = Ext.util.JSON.decode(obj.responseText);
- return result;
- }