Home > Backend Development > PHP Tutorial > ajax3—php (29), ajax3php29_PHP tutorial

ajax3—php (29), ajax3php29_PHP tutorial

WBOY
Release: 2016-07-13 09:53:11
Original
1003 people have browsed it

ajax3—php (29), ajax3php29

1. Application of json in Ajax

For processing of large batches of data:

1) xml

2) json

1. About json

An object is an unordered collection of attributes

In js, you can use {} to simulate an unordered collection of attributes

1. About json in php

Currently, most ajax programs use json objects as data transfer methods, so many languages ​​have built-in support for json objects. In php, there are two functions for encoding and decoding json

l string json_encode ( mixed $value )

Generate string in json format

l mixed json_decode ( string $json [, bool])

Parse json

The second parameter indicates whether to parse into an array or an object. The default is false, which means parsing into an object

1) json_encode

If you want to get data in json format, you must first get an array or object

2) json_decode

3) json_decode

Json currently only supports utf-8 format

3. Ajax uses json

Example 1: Using json to return four arithmetic operations of two numbers

Server code:

Example 2: Return multiple pieces of data from the server

Ajax program:

Php program:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1004400.htmlTechArticleajax3—php (29), ajax3php29 1. Application of json in Ajax for processing of large batches of data: 1) xml 2) json 1. About json object is an unordered collection of attributes in js, you can use...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template