How to solve an AJAX request that contains an array

Source: Internet
Author: User
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.

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.