This article mainly introduces how to solve the problem of the AJAX request containing the array, the text gives the detailed example code, I believe that everyone's understanding and learning is very helpful, the need for friends to follow the small series together to see it. Hope to help everyone.
Everyone should have found out. When we send an AJAX request with an array, we can't just put it in data and send it to the backend like normal JSON data.
For example, there is a data that needs to be sent to the backend:
{ "orderId": " Resourcejson": [ { "carcapacity": 223, "Carnumber": "123", "Driverinfo": "123", "Failreason": "3123123", "id": +, "Ispass": 0, "lineId": 784, "Load_plan": "123", "Onpackageday": 123, "price": 123, "storeoutcapacity": 123, "store_out_capacity": 123 }, { "Failreason": "31231231", "id": 2, "Ispass": 0, "lineId": 787, "Load_plan": "123", "store_out_capacity": 123, "Tallyman": "DDD" }, { "Failreason": "123123", "id": 1, "Ispass": 0, "lineId": 785, "Load_plan": "123", "store_out_capacity": 123, "Tallyman": " FFF " } ]}
Where the Resourcejson field is an array, and if you pass this JSON data directly to the background
The data you get in the background is like this:
The browser will automatically put the array solution into a variable, the background to get this data directly silly.
So, the best way is to put the array programming string, very simple, the array is stored separately with a variable, and then JSON.stringify
(array), the resulting string into the JSON data, so that the browser will not automatically help you to deconstruct the array, the background is a real array.