The previous article "JSON Advanced Part 1: Using JSON in PHP and JavaScript" demonstrated how to use JSON type data in PHP and JavaScript. This article will introduce the use of AJAX to obtain JSON data to dynamically generate titles and prompt statements. This technology is more effective when a static page requests dynamic data from the website background. Because the website homepage has a relatively large number of visits, the entire page needs to be processed statically, but some data on this page needs to be updated in real time. In this case, it can be AJAX is used in static pages to request JSON data generated in real time by the background. For information about AJAX technology, please refer to "PHP Access MySql Database - Advanced AJAX Technology". Here is a detailed introduction on how to use AJAX to transfer JSON data.
This sample program is divided into json2.php and json2.html. There is a button on json2.html. When pressed, an AJAX request will be sent to obtain the data returned by json2.php.
1. json2.php
[php]
// by MoreWindows( http://blog.csdn.net/MoreWindows )
$article_array = array(
"count" => 3,
array(
"id"=>"001",
"title"=>"Access MySql Database with PHP - Elementary",
"link"=>"http://www.BkJia.com/kf/201112/115227.html"
),
array(
"id"=>"001",
"title"=>"PHP Access MySql Database Intermediate Smarty Technology",
"link"=>"http://www.BkJia.com/kf/201112/115229.html"
),
array(
"id"=>"001",
"title"=>"PHP Access MySql Database Advanced AJAX Technology",
"link"=>"http://www.BkJia.com/kf/201112/115230.html"
),
);
$article_json = json_encode($article_array);
echo $article_json;
?>
2. Json2.html
[html]