加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax框架(UTF-8编码),POST传输

发布时间:2020-12-16 01:03:54 所属栏目:百科 来源:网络整理
导读:/* * The source code for this program is not published or otherwise divested of * its trade secrets. * */ /** Ajax 请求的封装类 * Example: * //实例化一个请求对象 * var ajaxObj = new AjaxProxyII(); * //设置ajax请求的url * ajaxObj.setRequest

/*
* The source code for this program is not published or otherwise divested of
* its trade secrets.
*
*/

/** Ajax 请求的封装类 * Example: * //实例化一个请求对象 * var ajaxObj = new AjaxProxyII(); * //设置ajax请求的url * ajaxObj.setRequestUrl("localhost/projectName/path/someAction.action") * //设置回调函数 回调函数 要有两个参function someFunc(data,textStatus); * ajaxObj.setOnSuccess(someFunc); * //设置要传递的参数 如果参数是对象形式 * ajaxObj.addParaObj(paraObject); * //如果参数为键值对形势 * ajaxObj.addParameter("key",value); * //设置同步异步 默认为异步 * ajaxObj.setAsync(false); * //发送请求 * ajaxObj.sendRequest(); */ var AjaxProxyII = function(){ this.parameter = new Object(); this.pojoPackagePath = "com.taiyang.search.bean"; this._props = new Object(); this._argArray = new Array(); this._pojoName = ''; this._paraStr = ''; this._props['asyn'] = true; this.setPojoName = function(pojoName){ this._pojoName = this.pojoPackagePath + pojoName ; } this.setRequestUrl = function(url){ this._props['url'] = url; } this.setOnSuccess = function(func){ this._props['onSuccess'] = func; } this.addParaObj = function(obj){ this._argArray.push(obj); } this.sendRequest = function(){ var callfunc=this._props['onSuccess']; this.setupParaStr(); $.ajax({ type : 'POST',url : this._props['url'],success :function(data){ if(data.indexOf('errormessage')>-1){ var tmpObj = eval( '(' + data + ')' ); if(tmpObj['errorcode']=="0"){ var windowsArr=new Array(); getWindowTop(window,windowsArr,tmpObj['errormessage']); return; }else if(tmpObj['errorcode']=="1"){ window.location.href=homeUrl+"/error.jsp?errormessage="+encodeURI(encodeURI(tmpObj['errormessage'])); return; } } callfunc(data); },data :this._paraStr,async : this._props['asyn'],error : function(data,textStatus){ //alert("错误" + data); } }); } this.setParaStr = function(str){ this._paraStr = str; } this.addParameter = function(key,value){ this.parameter['' + key] = value; } this.setAsync = function(flag){ this._props['asyn'] = flag; } this.setupParaStr = function(){ if(this._pojoName != 'undefined' && this._pojoName != ''){ this._paraStr += '&pojoName=' + this._pojoName + '&jsonData='; this._paraStr += JSON.stringify(this._argArray); } for(var i = 0 ; i<this._argArray.length; i++){ this._argArray[i] = null; } for(var p in this.parameter){ this._paraStr += p + '=' + this.parameter[p] + '&'; } //this._paraStr = "乱码" //this._paraStr = encodeURI(this._paraStr); } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读