<script type="text/javascript">
window.onload = function() {
document.getElementsByTagName("a")[0].onclick = function() {
var request = new XMLHttpRequest();
var method = "GET";
var url = this.href + "?time=" + new Date();
request.open(method, url);
request.send(null);
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200 || request.status == 304) {
alert(request.responseText);
}
}
}
return false;
}
}
</script>
</head>
<body>
<a href="hello.txt">Ajax hello.txt</a>
</body>
热门评论
<title>Ajax post</title>
<script type="text/javascript">
window.onload = function() {
document.getElementsByTagName("a")[0].onclick = function() {
var request = new XMLHttpRequest();
var method = "POST";
var url = this.href + "?time=" + new Date();
request.open(method, url);
request.setRequestHeader("ContentType", "application/x-www-form-urlencoded");
request.send("name='a'");
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200 || request.status == 304) {
alert(request.responseText);
}
}
}
return false;
}
}
</script>
</head>
<body>
<a href="hello.txt">Ajax hello.txt</a>
</body>