JSP pages passing object arrays to the back-end requirements
Jsp:
1 //Save2 $ ("#submitBtn"). Click (function () {3 var flag = true;4 var eachflag = true;5 var len = $ (". Resttable tbody"). Find ("tr"). Length;6 var arr = new Array ();7 if (len! = 0) {8 var trindex = 0;9 $ (". Financialtable tbody TR"). each (function () {Ten if (!eachflag) { One return; A } - trindex++; - var chargeuser = new Object (); the if ($ (this). Find (". Name"). Val (). Trim () = = ") { - layer.tips ("Please fill in the main person name", $ (". Financialtable #tr_" +trindex+ ". Name"), {time:1000}); - flag = false; - Eachflag = false; + return; - }else{ + Chargeuser.join_user = $ (this). Find (". Name"). Val (). Trim (); A } at if ($.trim (this). Find (". Sex"). val ()) = = ") { - layer.tips ("Please select the main person in charge of gender!", $ (". Financialtable #tr_" +trindex+ ". Sex"), {time:1000}); - flag = false; - Eachflag = false; - return; - }else{ in Chargeuser.sex = $ (this). Find (". Sex"). val () = = "Male"? 0:1; - } to if ($.trim (this). Find (". Phone"). val ()) = = ") { + layer.tips ("Please fill in the main person's phone", $ (". Financialtable #tr_" +trindex+ ". Phone"), {time:1000}); - flag = false; the Eachflag = false; * return; $ }else{Panax Notoginseng if (! (/^1[3|4|5|7|8| 9][0-9]\d{8}$/.test (This). Find (". Phone"). Val (). Trim () ))) { - layer.tips ("Please enter the correct phone", $ (". Financialtable #tr_" +trindex+ ". Phone"), {time:1000}); the flag = false; + Eachflag = false; A return; the }else{ + Chargeuser.phone = $ (this). Find (". Phone"). Val (). Trim (); - } $ } $ //ID card non-mandatory loss - if ($ (this). Find (". Card"). Val (). Trim ()! = ") { - var reg =/(^\d{18}$) | (^\d{17} (\d| X|X) $)/; the if (!reg.test (this). Find (". Card"). Val (). Trim ())) { - layer.tips ("Please enter the correct ID number", $ (". Financialtable #tr_" +trindex+ ". Card"), {time:1000});Wuyi flag = false; the Eachflag = false; - return; Wu } - } About $ var Id_card; - if ($ (this). Find (". Card"). Val (). Trim () = = ") { - chargeuser.id_card = Id_card; - }else{ A Chargeuser.id_card = $ (this). Find (". Card"). Val (). Trim (); + } the var postal_address; - if ($ (this). Find (". Address"). Val (). Trim () = = ") { $ chargeuser.postal_address = postal_address; the }else{ the chargeuser.postal_address = $ (this). Find (". Address"). Val (). Trim (); the } the //chargeuser.memo = $ (this). Find (". Memo"). Val (). Trim (); - var memo; in if ($ (this). Find (". Memo"). Val (). Trim () = = ") { the Chargeuser.memo = Memo; the }else{ About Chargeuser.memo = $ (this). Find (". Memo"). Val (). Trim (); the } the Chargeuser.pk_project_vendor = PK; the Arr.push (Chargeuser) + }) - } the if (!flag) {Bayi return; the } the $.ajax ({ - URL: "${ctp}/basic_project/vendor/chargeuser.json", - type: "Post", the dataType: "JSON", the data:{' arr ': json.stringify (arr), the ' Pk_project_vendor ':p K, the ' uuid ': UUID, - ' Pkold ':p kold the }, the Async:false, the Traditional:true,94 success:function (Result) { the if (result.success) { the layer.msg (result.msg, {time:1000}, function () { the Top.layer.close (layerindex);98 }); About }else{ - Layer.alert (Result.msg,{shift:2,closebtn:false},function () {101 Top.layer.close (layerindex);102 });103 }104 flag = true; the Eachflag = true;106 }107 })108})
The JSP page has three key points:
1. Define an array: var arr = new Array ();
2, define an object, and iterate to add the object properties, and finally push into the array
var chargeuser = new Object ();
Chargeuser.join_user = $ (". Financialtable. Name"). Val ();
Chargeuser.sex = $ (". financialtable. Sex"). val () = = "Male"? The 0:1;//database is of type int
Chargeuser.phone = $ (". financialtable. Phone"). Val ();
Chargeuser.id_card = $ (". financialtable. Card"). Val ();
Chargeuser.postal_address = $ (". Financialtable. Address"). Val ();
Chargeuser.memo = $ (". Financialtable. Memo"). Val ();
Arr.push (Chargeuser);
3. Convert array object at commit: data:{' arr ': Json.stringify (arr)},
Background Java receive:
JSP passes array arrays to the background