更新时间:2023-08-31 18:35:22
使用 JSON 作为数据类型在 PHP (后端)和 Javascript之间进行通信强>(前端).示例:
Use JSON as the datatype to communicate between PHP(Backend) and Javascript(Frontend). Example:
<?
$person = array("name"=>"Jon Skeet","Reputation"=>"Infinitely Increasing");
header("Content-Type: application/json");
echo json_encode($person);
?>
$.ajax({
url: "your_script.php",
dataType: "JSON"
}).success(function(person) {
alert(person.name) //alerts Jon Skeet
});