我的第一个ajax网页

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>Insert title here</title>
</head>
<body>
<script type=”text/javascript”>
function mm(){
window.alert(“hi”);
var xhr = new XMLHttpRequest();
xhr.open(“GET”,”g.xml”,true);
xhr.send();
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
/* var res = xhr.responseXML; */
var res = xhr.responseText;
document.getElementById(“we”).innerHTML = res;
window.alert(res);
}else{
window.alert(“页面不正常。”);
}
};
window.alert(“end”);
}
</script>
<script type=”text/javascript”>
function processResponse(){
if(xhr.readyStatus == 4 && xhr.status = 200){
var res = XMLHttpRequest.responseXML;
window.alert(res);
}else{
window.alert(“页面不正常。”);
}
}
</script>
<p id=”we”>we</p>
<button type=”button” onclick=”mm()”>me</button>

</body>
</html>

Author: bkdwei