ajax 案例demo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>新建网页</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <script type="text/javascript" src="jquery-2.1.3.min.js"></script> <script type="text/javascript"> function f1(){ //$.ajax(json参数) $.ajax({ url:'16.php', data:{addr:'北京','people':'2000',area:'10万',on:'123'}, dataType:'json', type:'post', success:function(msg){ //msg接收服务器端返回的数据 dump_obj(msg); //alert(msg.name+'--'+msg.age); } }); } </script> <script type="text/javascript"> function dump_obj(myObject) { var s = ""; for (var property in myObject) { s = s + "\n "+property +": " + myObject[property] ; } alert(s); } </script> <style type="text/css"> </style> </head> <body> <h2>ajax调用</h2> <input type="button" value="触发" onclick="f1()" /> </body> </html>
<?php echo json_encode($_POST); //echo json_encode(array('name'=>'linken','age'=>'20'));