JavaScript encapsulates the data code passed by Ajax

Source: Internet
Author: User

Copy codeThe Code is as follows: 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 ");
},
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;
};

After writing this article for a while, I couldn't mention it for a long time on csdn. I switched to advanced editing using IE6, and the content was blank. Finally, I used the Firefox browser to bring it up again ..

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.