Solution of an AJAX request containing an array _ajax related

Source: Internet
Author: User

Everyone should have found out that when we send an AJAX request with an array in the data, it can't be sent back to the background like normal JSON data.

For example, there is a data that needs to be sent back to the background:

{
  "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, if you pass this JSON data directly to the background

The data from backstage is this way:

The browser will automatically make the array solution to form a variable, backstage to get this data directly silly force.

So, the best way to do this is to put the array in a programming string, simply by saving the array with a variable, and then JSON.stringify (the array), putting the resulting string in the JSON data so that the browser doesn't automatically deconstruct the array, and the backend gets a real array.

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.

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.