Ajax3-php (29), ajax3php29

Source: Internet
Author: User

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:

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.