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

前端之家收集整理的这篇文章主要介绍了Ajax框架(UTF-8编码),POST传输前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

/*
* 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); } }

原文链接:https://www.f2er.com/ajax/166382.html

猜你在找的Ajax相关文章