Ajax requests return JSON data

Source: Internet
Author: User

Describes the method of using AJAX to request data from the server, and the use of the returned JSON data.

1 $.ajax ({2Type: "POST",3Asyncfalse,4URL: ********5data:{"province": $ ("#provice"). Val (),6"City": $ ("#city"). Val (),7"Area": $ ("#area"). Val ()},8DataType: "JSON",9Successfunction(data) {Ten                      //callback function to request data success One             } AErrorfunction(Error) { -                     //callback function for request data failure -             } the})

General data requests, these attributes are sufficient. Here's a little bit about these properties:
' Type ' requests data in the same way as Post

"Async" is set to True by default, which is an asynchronous request. When set to False is a synchronous request

The URL handles the requested address

The data sent to the server by "data". Note: The server-determined data name before the colon, followed by the corresponding value to be sent to the server for the corresponding data name

The data type of the "DataType" request is JSON

The Ok,ajax request is basically the case. Let's talk about the use of JSON data.

1, shaped like data=[' rice cooker ', ' refrigerator ', ' air conditioner ', ' induction cooker ', ' electric kettle ', ' thermal blanket ' JSON data

Similar to arrays. Can be queried or traversed directly using data[i], e.g. data[2]= "Air conditioning"

2, shape such as data=[{"id": 1, "name": "Zhang San"},{"id": 2, "name": "John Doe"},{"id": 3, "name": "Wang er"}]

An array that resembles an owning property. Get a piece of data through data[i] and use. Name to get the value of the corresponding name

For example: data[1]={"id": 2, "name": "John Doe"},

Data[1].name= "John Doe"

The end of this article.

You are welcome to correct me!

Ajax requests return JSON data

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.