Home Web Front-end JS Tutorial How to implement AJAX request array

How to implement AJAX request array

Apr 03, 2018 am 09:55 AM
ajax how

This time I will show you how to implement the AJAX request array, and what are the precautions for the AJAX request array. The following is a practical case, let's take a look.

Everyone should have discovered that when we send an AJAX request with an array in the data, it cannot be directly placed in the data and sent to the background like ordinary JSON data.

For example There is such a data that needs to be sent to the background:

{
  "orderId": 22,
  "resourceJson": [
    {
      "carCapacity": 223,
      "carNumber": "123",
      "driverInfo": "123",
      "failReason": "3123123",
      "id": 25,
      "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"
    }
  ]
}
Copy after login
The resourceJson field is an array. If you directly pass this JSON data to the background

The data obtained by the background is this Looks like:

The browser will automatically decompose the array into individual

variables, and it will be stupid to get this data in the background.

So, the best way is to program the array

String, very simple, store the array in a separate variable, and thenJSON.stringify (array), put the obtained string into JSON data, so that the browser will not automatically deconstruct the array for you, and what you get in the background is a real array.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to deal with ajax cross-domain access error 501

Use Ajax to increase data based on the human resources system OA account method

The above is the detailed content of How to implement AJAX request array. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

How to solve the 403 error encountered by jQuery AJAX request

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

How to solve jQuery AJAX request 403 error

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

How to get variables from PHP method using Ajax?

How to solve the problem of jQuery AJAX error 403? How to solve the problem of jQuery AJAX error 403? Feb 23, 2024 pm 04:27 PM

How to solve the problem of jQuery AJAX error 403?

PHP vs. Ajax: Solutions for creating dynamically loaded content PHP vs. Ajax: Solutions for creating dynamically loaded content Jun 06, 2024 pm 01:12 PM

PHP vs. Ajax: Solutions for creating dynamically loaded content

Understanding Ajax Frameworks: Explore Five Common Frameworks Understanding Ajax Frameworks: Explore Five Common Frameworks Jan 26, 2024 am 09:28 AM

Understanding Ajax Frameworks: Explore Five Common Frameworks

Asynchronous data exchange using Ajax functions Asynchronous data exchange using Ajax functions Jan 26, 2024 am 09:41 AM

Asynchronous data exchange using Ajax functions

What are the ajax versions? What are the ajax versions? Nov 22, 2023 pm 02:00 PM

What are the ajax versions?

See all articles