码迷,mamicode.com
首页 > Web开发 > 详细

AJAX调用PHP简单应用

时间:2016-09-02 16:15:34      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:php

HTML页面

<html>  
    <head>  
    </head>  
    <body>  
       <form action="7.php">
       	<input type="text" name="name">
		<input type="text" name="pass">
		<input type="text" name="age">
		<input type="button" value="提交" onclick="a();"> 
       </form>
       <script src="js\jquery-1.11.2.min.js"></script>
       <script>
       	function a(){
       		var cont=$("input").serialize();
	$.ajax({
		url:"7.php",
		type:‘post‘,
		data:cont,
		success:function (data){
		var res = 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页面

<?php  
$name=$_POST["name"];
$pass=$_POST["pass"];
$age=$_POST["age"];
 $arr=array("name"=>$name,"pass"=>$pass,"age"=>$age);
$arr=json_encode($arr);
echo $arr;
?>


AJAX调用PHP简单应用

标签:php

原文地址:http://sr0517.blog.51cto.com/809286/1845540

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!