JSON Advanced Part 2 AJAX Way to Pass JSON Data_PHP Tutorial

WBOY
Release: 2016-07-13 17:48:33
Original
1045 people have browsed it

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]



Request json via ajax

 
 

    
 
 
 
 

 
 
 
运行效果如下:
 
 
 
下一篇《JSON进阶第三篇apache多域名及JSON的跨域问题(JSONP)》将展示JSON的跨域问题并给出解决方案。
 
 
 
转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/7206390

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478434.htmlTechArticle上一篇《JSON进阶第一篇 在PHP与javascript 中使用JSON》示范了在PHP和javascript中如何使用JSON类型的数据,本篇将介绍用AJAX方式得到JSON数据从而...
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