Javascript encapsulates data transmitted by Ajax

Source: Internet
Author: User
Tags javascript array
Javascript array # Join When Using ajax to transmit data, it is essential to transcode the passed characters. My implementation method is to save the data to a JS bean, place the JS bean in the array. When the transmission parameter is generated, the jsbean in the array is decomposed to obtain the corresponding attribute information and encode it ..

VaR parambeanlist = new array (); <br/> array. prototype. addparambean = function (parambeanobj) {<br/> var Index = This. containparambean (parambeanobj); <br/> If (index! =-1) {<br/> This [Index] = parambeanobj; <br/>}else {<br/> This. push (parambeanobj); <br/>}< br/>}; <br/> array. prototype. clear = function () {<br/> If (this. length = 0) {<br/> return; <br/>}< br/> for (VAR index in this) {<br/> This. pop (); <br/>}< br/>}; <br/> array. prototype. containparambean = function (parambeanobj) {<br/> var Index =-1; <br/> If (this. length = 0) {<br/> Return Index; <br/>}< br/> for (VA R tempindex = 0, step = This. length; tempindex <step; tempindex ++) {<br/> If (this [tempindex]. compare (parambeanobj) = 0) {<br/> Index = tempindex; <br/> break; <br/>}< br/> Return Index; <br/>}; <br/> var parambean = new function (pkcode, opdate, value) {<br/> This. pkcode = pkcode; <br/> This. opdate = opdate; <br/> This. value = value; <br/>}; <br/> parambean. prototype = {<br/> tostring: function () {<Br/> return "[pkcode:" + this. pkcode + ", opdate:" + this. opdate + ", value:" + this. value + "]"; <br/>}, <br/> doverify: function () {<br/> return (this. pkcode? This. opdate? This. value? "True": "false"); <br/>}, <br/> compare: function (otherobj) {<br/> var result =-1; <br/> If (otherobj) {<br/> If (this. pkcode = otherobj. pkcode & this. opdate = otherobj. opdate <br/> & this. value = otherobj. value) {<br/> result = 0; <br/>}< br/> return result; <br/>}< br/> }; <br/> var paramutils = new object (); <br/> paramutils. docreateajaxstr = function () {<br/> var paramstr = ""; <br/> If (parambeanlist. length = 0) {<br/> return paramstr; <br/>}< br/> var keyparamarray = new array (); <br/> var valueparamarray = new array (); <br/> for (VAR Index = 0, step = parambeanlist. length; index <step; index ++) {<br/> var tempobj = parambeanlist [Index]; <br/> keyparamarray. push (tempobj. pkcode + "'" + tempobj. opdate); <br/> valueparamarray. push (tempobj. value); <br/>}< br/> paramstr = "key_param = ". concat (encodeuricomponent (keyparamarray. join (","))). concat ("&"). concat ("value_param = ". concat (encodeuricomponent (valueparamarray. join (","); <br/> return paramstr; <br/> }; 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.