Ajax3-php (29), ajax3php29
I. json application in Ajax
Processing of large volumes of data:
1) xml
2) json
1. About json
An object is an unordered set of attributes.
In js, {} can be used to simulate unordered sets of attributes.
1. About json in php
Currently, most ajax programs use json objects for data transmission. Therefore, many languages have built-in support for json objects. In php, there are two functions used to encode and decode json.
L string json_encode (mixed $ value)
Generate a string in json format
L mixed json_decode (string $ json [, bool])
Parse json
The second parameter indicates whether it is parsed to an array or an object. The default parameter is false, indicating that it is parsed to an object.
1) json_encode
To obtain data in json format, you must first obtain an array or object.
2) json_decode
3) json_decode
Json currently only supports UTF-8 format
3. Ajax uses json
Example 1: return the four arithmetic operations of two numbers using json
Server code:
Example 2: Return multiple data records from the server
Ajax program:
Php program: