1、jQuery.php
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jQuery</title> <script src="jquery-3.3.1.min.js"></script> </head> <body> <script type="text/javascript"> $(function(){ // 单击按钮执行 $("#btnInfo").click(function() { var dataParam = { id: "9001", age: "28" }; // 调用处理 var html = $.ajax({ type: "post", url: "info.php", data: dataParam, //"id=9001&age=28", async: false }).responseText; $("#divInfo").html('<h2>'+html+'</h2>'); }); }) </script> <div id="divInfo"><h2>jQuery按钮事件</h2></div> <button id="btnInfo" type="button">jQuery</button> </body> </html>
2、info.php
<?php //$id = $_POST['id']; $id = $_REQUEST['id']; echo "hi, " . $id; //echo '[{"name":"9001","age":"28"},{"name":"9002","age":"29"},{"name":"9003","age":"30"},{"name":"9004","age":"31"},{"name":"9005","age":"32"},{"name":"9005","age":"33"}]'; ?>