首页 > Web开发 > 详细

php——phpAjax

时间:2015-10-12 01:47:05      阅读:159      评论:0      收藏:0      [点我收藏+]

技术分享

index.html

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="content-type" content="text/html;charset=utf-8">
 5     <title>phpAjax</title>
 6     <script type="text/javascript" src="js/jquery.js"></script>
 7 </head>
 8 <body>
 9     <label for="title">图书: </label>
10     <input type="text" name="title" id="title"><br/>
11     <label for="author">作者: </label>
12     <input type="text" name="author" id="author"><br/>
13     <input type="button" value="send" id="btn"><br/>
14     <span id="msg"></span>
15 </body>
16 <script type="text/javascript">
17     $(function(){
18         
19         $("#btn").click(function(event) {
20             var text = $("input").serialize();
21             $("#msg").html("");
22             $.ajax({
23                 type:"post",
24                 url:"test.php",
25                 dataType:"json",
26                 data:text,
27                 success:function(data){
28                     $("#msg").html("图书: "+data.title+"<br/>作者: "+data.author+"<br/>"+data.msg);
29                 }
30             });
31             $("#title").prop(value, ‘‘);
32             $("#author").prop(value, ‘‘);
33         });
34     }); 
35 </script>  
36 </html>

test.php

 1 <?php
 2     $title = $_POST["title"];
 3     $author = $_POST["author"];
 4 
 5     $arr = array(
 6         "title"=>$title,
 7         "author"=>$author,
 8         "msg"=>"恭喜您购得此书!!!"
 9     );
10 
11     if($title== "php" && $author == "phpauthor"){
12         echo json_encode($arr);
13     }
14 ?>

php——phpAjax

原文:http://www.cnblogs.com/yuge790615/p/4870551.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!