Ajax pass array, form form Submit Object array

Source: Internet
Author: User

In JSP page development, we often use form form to do data submission, because it used to only submit a single object using form form, as long as the form text field name value and the Received object's property name is consistent, then the value of the transfer is not a problem. However, in the development task of the previous days, encountered the need to bulk transfer objects, that is, the need to pass an array of objects, here is a summary. Today, I encountered the need to pass the array to the background, and then write it down.

1, Ajax pass Ordinary array
Front Code

var deletenum= [];//defines the array to be passed Deletenum.push ("1");d Eletenum.push ("2");d Eletenum.push ("3");//add element $.ajax to the array ({    Type: "Post",    URL: "deletenum.do",    data:{deletenum:deletenum},    traditional:true,//must be specified as True    Success:function (data) {        if (data.success) {            deletenum = [];}}    });

Background code

Public ActionResult Deletenum (string[] deletenum) {        //This time has got the Deletenum array value    return Json (new {Status=1});}

Form form submission Custom Object array

<form id= "form" name= "form"  method= "POST" >  <table>    <tr>      <td><input Type= "text" name= "User[0].name"/></td>      <td><input type= "text" name= "User[0].password"/> </td>    </tr>    <tr>      <td><input type= "text" name= "User[1].name"/></td >      <td><input type= "text" name= "User[1].password"/></td>    </tr>    <tr >      <td><input type= "text" name= "User[2].name"/></td>      <td><input type= "text "Name=" User[2].password "/></td>    </tr>  </table></form>

  After the form form is submitted to the background, you need to define an object, of course, do not forget to define the user object, the property is Name,password, the focus is the following to receive form form submission of the object array, if there are other object array to receive, Then define the corresponding ArrayList attribute in this class.

/** * 类型描述 * 表单列表对象 用于接收form表单提交的对象数组 * @since  2016-2-25 * @author 古时一轮月 * */public class FormListObject { private ArrayList<User> userlist; public ArrayList<User> getUserlist() { return userlist; } public void setUserlist(ArrayList<User> userlist) { this.userlist= userlist; }}

After the object is defined, it can be received at the controller layer.

Public Ajaxresult saveorupdateuser (formlistobject list) {    list<user> userlist = List.getuserlist (); You'll see what you want.}

Transferred from: http://blog.csdn.net/u014252157/article/details/50751302

Ajax pass array, form form Submit Object array

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.