不知哪里出错了,记下来
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
<script type="text/javascript">
window.onload = function() {
document.getElementsByTagName("a")[0].onclick = function() {
var xhr = new XMLHttpRequest();
var method = "GET";
var url = "helloAjax.txt";
xhr.open(method, url);
xhr.send("atguigu");
alert(111); //能输出
//直接报错误
xhr.onreadystatechange() = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status == 304) {
alert("^^^" + xhr.responseText);
}else{
alert(222);
}
}
}
return false;
}
}
</script>
</head>
<body>
<a href="helloAjax.txt"> HelloAjax </a>
</body>
</html>
注:onreadystatechange是ajax的一个属性,没有括号。
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————