File one: Front-end template file news.html.
Used to nest PHP statements after loading the database content to produce news.htmls static files.
File two: Articlelist.js file.
$.ajax ({//
interface address
URL: ' http://static.com/api/hot.php ',
//Request method
type: ' Get ',
//Return data type
DataType: ' JSON ',
//request failed when processing
error:function () {},
//Request succeeded when processing method
Success:function (Result) {
if (Result.code = = 1) {
//The data returned from the interface is assembled with HTML statement html
= ';
$.each (Result.data,function (key,value) {
html + = ' <li><a href= ' # # ' >+value.title+</li> ';
});
//Even if a static news.htmls file is requested, the static new.htmls file, JQ also dynamically adds the data to the static news.htmls static file in
$ ("#hot_html"). HTML (HTML);
else{
//todo
}
}
);
File three: interface file-news.php.
<?php
/*************** here ***************//
* Results from the database query and assembled into an array $arrres*/
/*********************** ///
Call the Show method to encapsulate and return the interface data back
to show (1, ', $arrRes);
Function Show ($code, $message, $data) {
$resule =array (
' code ' = + $code,
' message ' + $message,
' Data ' = $data,
);
Convert data into JSON data and output to make Ajax receive
echo Json_encode ($result);
}
? >