ajax实例


HTML部分:


<!DOCTYPE HTML>
<html>
<head>
<title>test</title>
<meta charset="utf-8" />
<script type="text/javascript">
function ajax(){
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET","get.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="button" value="确定" onclick="ajax()" />
</body>
</html>

php部分:get.php


<?php
echo 'success!';
?>

发表回复