JavaScript 封裝Ajax傳遞的數(shù)據(jù)代碼
更新時(shí)間:2009年06月05日 22:34:19 作者:
在使用Ajax傳輸數(shù)據(jù)時(shí),少不了對(duì)傳遞的字符進(jìn)行轉(zhuǎn)碼,我的實(shí)現(xiàn)方式是將需要傳遞的數(shù)據(jù)暫存到一js Bean中,將js Bean放到Array中,生成傳輸參數(shù)時(shí)對(duì)Array中的jsBean進(jìn)行分解,得到相應(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;
};
這篇文章我寫了一會(huì),到了csdn上弄了半天提不上去,我用IE6切到高級(jí)編輯,內(nèi)容直接就是空,最后用Firefox瀏覽器竟然又提上來(lái)了。。
您可能感興趣的文章:
- 一個(gè)AJAX自動(dòng)完成功能的js封裝源碼[支持中文]
- 原生Javascript封裝的一個(gè)AJAX函數(shù)分享
- js實(shí)現(xiàn)對(duì)ajax請(qǐng)求面向?qū)ο蟮姆庋b
- 原生JS封裝ajax 傳json,str,excel文件上傳提交表單(推薦)
- 淺析jQuery Ajax通用js封裝
- js鎖屏解屏通過(guò)對(duì)$.ajax進(jìn)行封裝實(shí)現(xiàn)
- js原生Ajax的封裝和原理詳解
- 使用原生js封裝的ajax實(shí)例(兼容jsonp)
- 純js封裝的ajax功能函數(shù)與用法示例
- 原生javascript實(shí)現(xiàn)的ajax異步封裝功能示例
- 原生js封裝的ajax方法示例
相關(guān)文章
網(wǎng)站導(dǎo)致瀏覽器崩潰的原因總結(jié)(多款瀏覽器) 推薦
對(duì)于訪客,如果登錄您網(wǎng)站,瀏覽器就立刻崩潰,我想這對(duì)誰(shuí)都是無(wú)法容忍的,對(duì)此總結(jié)了網(wǎng)站導(dǎo)致瀏覽器崩潰的原因2010-04-04JS?簡(jiǎn)單實(shí)現(xiàn)拖拽評(píng)星的示例代碼
本文主要介紹了JS?簡(jiǎn)單實(shí)現(xiàn)拖拽評(píng)星,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05詳解element-ui 表單校驗(yàn) Rules 配置 常用黑科技
這篇文章主要介紹了element-ui 表單校驗(yàn) Rules 配置 常用黑科技,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07JavaScript實(shí)現(xiàn)的簡(jiǎn)單煙花特效代碼
這篇文章主要介紹了JavaScript實(shí)現(xiàn)的簡(jiǎn)單煙花特效代碼,涉及JavaScript數(shù)學(xué)運(yùn)算及頁(yè)面元素基于定時(shí)函數(shù)運(yùn)動(dòng)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10Javascript無(wú)參數(shù)和有參數(shù)類繼承問題解決方法
這篇文章主要介紹了Javascript無(wú)參數(shù)和有參數(shù)類繼承問題解決方法,本文講解了無(wú)參數(shù)類繼承的問題和有參類繼承的問題,并給出了解決方案,需要的朋友可以參考下2015-03-03一個(gè)JavaScript遞歸實(shí)現(xiàn)反轉(zhuǎn)數(shù)組字符串的實(shí)例
這篇文章主要介紹了一個(gè)JavaScript遞歸實(shí)現(xiàn)反轉(zhuǎn)數(shù)組字符串的實(shí)例,很不錯(cuò),非常適合新手朋友們2014-10-10