tags: spring-mvc
var commditys = new Array();
var a = $('.cartList').find('tr:gt(0)');
var orderAmount = $('.prd-counter').find("input[name='orderAmount']").val();
var discountAmount = $('.prd-counter').find("input[name='discountAmount']").val();
var payAmount = $('.prd-counter').find("input[name='payAmount']").val();
a.each(function () {
var commdity = new Object();
commdity.cmmdtyCode = $(this).find("input[name='cmmdtyCode']").val();
commdity.cmmdtyName = $(this).find("input[name='cmmdtyName']").val();
commdity.unitPrice = $(this).find("input[name='unitPrice']").val();
commdity.sellPrice = $(this).find("input[name='sellPrice']").val();
commdity.totalPayAmount = $(this).find("input[name='totalPayAmount']").val();
commdity.quantity = $(this).find("input[name='quantity']").val();
commditys.push(commdity);
});
$.ajax({
method: 'post',
url: '/saveCart.do',
data: {
'buyerPhone': buyerPhone,
'orderAmount': orderAmount,
'discountAmount': discountAmount,
'payAmount': payAmount,
'userCode': employeeCode,
'commditys': JSON.stringify(commditys)
},
dataType: 'json',
success: function (data) {
if ("000000" == data.responseCode) {
showTips("Success!");
clearCart();
} else {
showTips("The form failed, please try again later!");
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
showTips("The form failed, please try again later!");
}
});
// 6, pending order
@RequestMapping(value = "saveCart", method = {RequestMethod.POST})
@ResponseBody
public String ajaxUpdateCart(@RequestParam String commditys,
@RequestParam String buyerPhone,
@RequestParam String orderAmount,
@RequestParam String discountAmount,
@RequestParam String payAmount,
@RequestParam String userCode
) {
String storeId = SessionUtils.getCurrentOperator().getStoreId();
// String storeId = "A1004";
JSONArray array = JSONArray.fromObject(commditys);
List<CommdityBean> list = JSONArray.toList(array, new CommdityBean(), new JsonConfig());
Response<String> response = shoppingCartService.createTempShopping(list, userCode, buyerPhone, storeId, orderAmount, discountAmount, payAmount);
return JSONObject.toJSONString(response);
}
Use Ajax to pass the JSON array to MVC background front end Front -end code: Background code:...
Front end AJAX: rear end One method is @RequestBody puts the json array of JSON in the string Arr, then use JSonarray to transfer to LIST...
Spring Boot Ajax Submit an Array JSON Import dependence JSON conversion used in this article is Ali's Fastjson 2. Entity class 3. Controller The difference between the modes 2 and the mode 3 is that o...
The front end of the following code, passing an array, receiving background List <String>: Background code as follows: There are two points to note: Use annotations@RequestParam Parameter values...
ajax spring the key code is @RequestParam(value=“overtimeids[]”)!!!...
Passing data in ajax can be used Background reception can be used: Note: The key is the $.ajax({traditional: true,}) setting, not the next String[] checkedIds can't receive the value. &n...
Ajax pass array: Ajax pass object: ...
Examples ...
Backstage $.ajax({ url: “/bill/distribute”, type: “post”, data: {“ids”: 1,2,3,4,5,}, dataType: “json”, success: function (data) { Global.success(success...
If you want to use ajax to pass the array to the background,traditional must be set to true。...