The php implementation makes the data into the json format for the front end to use
- 2021-10-27 06:42:11
- OfStack
interCom. php page
<?php
header('Content-Type: application/json; charset=utf8');
class Response{
/* interger $Status Status code 200/400
* string $Msg Prompt information
* array $Data Data
* return string Return value json Data returned
* */
public static function json($Status,$Msg,$Data=array()){
if(!is_numeric($Status)){ // Whether it is a number or not
return "";
}
// Assemble new data
$result=array(
'Status'=>$Status,
'Msg'=>$Msg,
'Data'=>$Data
);
// Become json Format
echo json_encode($result,JSON_UNESCAPED_UNICODE);//JSON_UNESCAPED_UNICODE Let Chinese not be coded
exit;
}
}
?>
list. php file
<?php
require_once("interCom.php");// Quote interCom.php Documents
//http://127.0.0.1/list.php?page=1&pagesize=12 //
$page=isset($_GET['page'])?$_GET['page']:1;
// If it exists, it is the passed value If not, assign it to 1
$pagesize=isset($_GET['pagesize'])?$_GET['pagesize']:1;
if(!is_numeric($page)||!is_numeric($pagesize)){
Response::json(401, " Illegal data "); //
}
?>
//The front end calls url of json data to see where list is placed on the local server. I use the wamp suite. Put it at http://127.0.0.1/workSpace/list. php, which is also the address requested by the client, but what parameters should be passed to this address? page & pagesize Try the following one to understand.
http://127.0.0.1/workSpace/list.php?page=xsxs