test_ajax_get.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ajax_get方式</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="keywords" content="html,css,js,ajax" />
<style type="text/css"> </style>
<script type="text/javascript">
function fun()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test_ajax_get.php?name='xiaoming'",true);
xmlhttp.send();
}
</script>
</head>
<body>
<h1>ajax_get提交方式</h1>
<div><input type="button" value="点我" onclick="fun()" /></div>
<div id="myDiv"></div>
</body>
</html>
test_ajax_get.php
<?php
header("Content-type:text/html;charset=utf8");
$name=$_GET["name"];
echo $name." hello world";
?>
ps:
print_r(); 用于输出数组