JavaScript 封裝Ajax傳遞的數(shù)據(jù)代碼
更新時間:2009年06月05日 22:34:19 作者:
在使用Ajax傳輸數(shù)據(jù)時,少不了對傳遞的字符進行轉(zhuǎn)碼,我的實現(xiàn)方式是將需要傳遞的數(shù)據(jù)暫存到一js Bean中,將js Bean放到Array中,生成傳輸參數(shù)時對Array中的jsBean進行分解,得到相應(yīng)屬性信息并編碼..
復(fù)制代碼 代碼如下:
var paramBeanList = new Array();
Array.prototype.addParamBean=function(paramBeanObj){
var index = this.containParamBean(paramBeanObj);
if (index != -1) {
this[index] = paramBeanObj;
} else {
this.push(paramBeanObj);
}
};
Array.prototype.clear=function(){
if (this.length == 0) {
return;
}
for (var index in this) {
this.pop();
}
};
Array.prototype.containParamBean=function(paramBeanObj){
var index = -1;
if (this.length == 0) {
return index;
}
for (var tempIndex = 0, step = this.length; tempIndex < step; tempIndex++) {
if (this[tempIndex].compare(paramBeanObj) == 0) {
index = tempIndex;
break;
}
}
return index;
};
var ParamBean = new function(pkCode, opDate, value) {
this.pkCode = pkCode;
this.opDate = opDate;
this.value = value;
};
ParamBean.prototype={
toString:function() {
return "[pkCode:" + this.pkCode + ",opDate:" + this.opDate +",value:" + this.value + "]";
},
doVerify:function() {
return (this.pkCode ? this.opDate ? this.value ? "true" : "false" : "false" : "false");
},
compare:function(otherObj) {
var result = -1;
if (otherObj) {
if (this.pkCode == otherObj.pkCode && this.opDate == otherObj.opDate
&& this.value == otherObj.value) {
result = 0;
}
}
return result;
}
};
var ParamUtils = new Object();
ParamUtils.doCreateAjaxStr=function() {
var paramStr = "";
if (paramBeanList.length == 0) {
return paramStr;
}
var keyParamArray = new Array();
var valueParamArray = new Array();
for (var index = 0, step = paramBeanList.length; index < step; index++) {
var tempObj = paramBeanList[index];
keyParamArray.push(tempObj.pkCode + "`" + tempObj.opDate);
valueParamArray.push(tempObj.value);
}
paramStr = "KEY_PARAM=".concat(encodeURIComponent(keyParamArray.join(","))).concat("&").concat("VALUE_PARAM=".concat(encodeURIComponent(valueParamArray.join(","))));
return paramStr;
};
這篇文章我寫了一會,到了csdn上弄了半天提不上去,我用IE6切到高級編輯,內(nèi)容直接就是空,最后用Firefox瀏覽器竟然又提上來了。。
相關(guān)文章
網(wǎng)站導(dǎo)致瀏覽器崩潰的原因總結(jié)(多款瀏覽器) 推薦
對于訪客,如果登錄您網(wǎng)站,瀏覽器就立刻崩潰,我想這對誰都是無法容忍的,對此總結(jié)了網(wǎng)站導(dǎo)致瀏覽器崩潰的原因2010-04-04詳解element-ui 表單校驗 Rules 配置 常用黑科技
這篇文章主要介紹了element-ui 表單校驗 Rules 配置 常用黑科技,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07Javascript無參數(shù)和有參數(shù)類繼承問題解決方法
這篇文章主要介紹了Javascript無參數(shù)和有參數(shù)類繼承問題解決方法,本文講解了無參數(shù)類繼承的問題和有參類繼承的問題,并給出了解決方案,需要的朋友可以參考下2015-03-03一個JavaScript遞歸實現(xiàn)反轉(zhuǎn)數(shù)組字符串的實例
這篇文章主要介紹了一個JavaScript遞歸實現(xiàn)反轉(zhuǎn)數(shù)組字符串的實例,很不錯,非常適合新手朋友們2014-10-10