JS Ajax Pass list array to background

Source: Internet
Author: User

http://blog.csdn.net/lingxyd_0/article/details/10428785

Today in writing code, encountered the problem, Baidu, found that the original Ajax passed the list data is possible, and has been used in JSON serialization (new array () array settings) for the value.

var_list = {};  Equivalent to Var _list=new Object ();  for(vari =0; I <Ten; i++) {_list["receive name in background controller ["+ i +"]"] =value;//Set the object's Key=>value key-value pair, which is similar to the a[0]=0 content into the object _list, for background receive, is equivalent to the list content} $.ajax ({URL:'the path passed', Data: _list,//Direct _list section can be, equivalent to data: {"Ids[0]": 1, "ids[1]": 2} This notation DataType:"JSON", type:"POST", Success:function (data) {alert ('Ok');  }  }); 

Another way to array pattern

<script>varA=[];//Set Array mode     for(vari =0; I <Ten; i++) {A[i]=i; }    //var B = $.param (A, true);$.ajax ({URL:"/jsaction/edit",        //data:{"IDs": B}, this way I test the number of data obtained here is 0, not NULL, norDataType:"JSON", type:"Post", data: {"IDs": A},//using this array method, you have to add the next sentence to use the traditional wayTraditional:true, Success:function (data) { for(vari =0; i < data.length; i++) {Console.log (data[i]); }        }    })</script>

JS Ajax Pass list array to background

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.