ajax_get方式

test_ajax_get.html

 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 2 <html>
 3     <head>
 4         <title>ajax_get方式</title>
 5         <meta http-equiv="content-type" content="text/html;charset=utf-8" />
 6         <meta name="keywords" content="html,css,js,ajax" />
 7         <style type="text/css">
 8             
 9         </style>
10         <script type="text/javascript">
11             function fun()
12             {
13                 var xmlhttp;
14                 if (window.XMLHttpRequest)
15                 {// code for IE7+, Firefox, Chrome, Opera, Safari
16                     xmlhttp=new XMLHttpRequest();
17                 }
18                 else
19                 {// code for IE6, IE5
20                     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
21                 }
22                 xmlhttp.onreadystatechange=function()
23                 {
24                     if (xmlhttp.readyState==4 && xmlhttp.status==200)
25                     {
26                         document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
27                     }
28                 }
29                 xmlhttp.open("GET","test_ajax_get.php?name='xiaoming'",true);
30                 xmlhttp.send();
31             }
32         </script>
33     </head>
34     <body>
35         <h1>ajax_get提交方式</h1>
36         <div><input type="button" value="点我" onclick="fun()" /></div>
37         <div id="myDiv"></div>
38     </body>
39 </html>

 

test_ajax_get.php

1 <?php
2     header("Content-type:text/html;charset=utf8");
3     $name=$_GET["name"];
4     echo $name." hello world";
5 ?>

ps:

print_r();   用于输出数组

posted @ 2016-12-01 16:21  自在飞花轻似梦  阅读(181)  评论(0编辑  收藏  举报