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