The front-end transmits multiple pieces of data from the form to the background for reception (the multiple pieces of data in the HTML front-end form are encapsulated in JSON; asynchronously submitted to the background for processing)
1. Multiple pieces of data are carried by checkBox
// object that encapsulates data var PayObj = { O_NBR:"", P_NBR:"", O_AMOUNT:"" , P_DT:"", P_HL_ZH:"", P_PAY_TYP:"", P_POS:"", P_U_ZH:"", P_U_HM:"", P_ATTR_IMGS:"", P_RECEIPT_NBR:"" }
var a = JSON.parse("{\"title\":\"\",\"data\":[]}");2. Traverse the table to encapsulate the data: (each row of the table is a JSON object; multiple rows are a JSON array, and the JSON array is making an object)
function getChecked() { $('input[name="check[]"]:checked').each(function() { var PayObj = new Object(); roleids += $(this).val() + ","; requestTransNo += $(this).val() + ","; cardNo += $(this).attr('cardNo') + ","; cardUser += $(this).attr('cardUser') + ","; refundAmt += $(this).attr('refundAmt') + ","; tranNo += $(this).attr('tranNo') + ","; dealDate += $(this).attr('dealDate') + ","; orderId += $(this).val() + ","; PayObj.requestTransNo = $(this).val(); PayObj.cardNo = $(this).attr('cardNo'); PayObj.cardUser = $(this).attr('cardUser'); PayObj.dealDate = $(this).attr('dealDate'); PayObj.orderId = $(this).val(); PayObj.tranNo = $ (this) .attr ('tranNo'); PayObj.refundAmt = $(this).attr('refundAmt'); PayObj.refundReason = document.getElementById('refundReason').value; alert(document.getElementById('refundReason').value); a.data.push(PayObj);//The method of adding JSON objects to the JSON array; very important }); }
3
///Format the data var obj=JSON.stringify(a);//This line is critical
$.ajax({ type: "post", url : "${ctx}/refund/transferPaymentReback/ajaxRefundTransferPaymentReback.do", dataType: "json", cache: true, data:{'param':obj}, success: function (data) { showAlertMsg(data.flag.errorMsg, { closeFunction: function () { if (data.flag.success == true) { window.location.href="${ctx}/member/relation/bankOfHuaXiaManager.do" } } }); }, error: function () { alertMsg(null, false, null, null, "Failed to call the interface, please try again later!"); } });
5. Background parsing and receiving data
String param = request.getParameter("param"); JSONObject json=JSONObject.fromObject(param); List<Map<String,String>> payList=json.getJSONArray("data");