HTML页面
<html> <head> </head> <body> <formaction="7.PHP"> <inputtype="text"name="name"> <inputtype="text"name="pass"> <inputtype="text"name="age"> <inputtype="button"value="提交"onclick="a();"> </form> <scriptsrc="js\jquery-1.11.2.min.js"></script> <script> functiona(){ varcont=$("input").serialize(); $.ajax({ url:"7.PHP",type:'post',data:cont,success:function(data){ varres=eval("("+data+")");//转为Object对象 document.write("name:"+res["name"]+"<br>"); document.write("pass:"+res["pass"]+"<br>"); document.write("age:"+res["age"]+"<br>"); } }) } </script> </body> </html>
<?PHP $name=$_POST["name"]; $pass=$_POST["pass"]; $age=$_POST["age"]; $arr=array("name"=>$name,"pass"=>$pass,"age"=>$age); $arr=json_encode($arr); echo$arr; ?>