Initial application of ajax



  

 



 

 

<%@ 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>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

<script type="text/javascript">

window.onload = function() {

//1. Get the a node and add the onclick response function to it

document.getElementsByTagName("a")[0].onclick = function() {

 

//3. Create an XMLHttpRequest object

var request = new XMLHttpRequest();

//4. Prepare to send the requested data: url;

var url = this.href;

var method = "GET";

//5. Call the open method of the XMLHttpRequest object

request.open(method, url);

//6. Call the send method of the XMLHttpRequest object

request.send(null);

//7. Add onreadystatechange response function to XMLHttpRequest object

request.onreadystatechange = function() {

//8. To judge whether the response is complete, when the readyState property value of the XMLHttpRequest object is 4

if (request.readyState == 4) {

//9. Then judge whether the response is available: the value of the status attribute of the XMLHttpRequest object is 200

if (request.status == 200 || request.status==304) {

alert(request.responseText);

}

 

}

 

}

//2. Cancel the default behavior of a node

return false;

}

 

}

</script>

</head>

<body>

<a href="hallow.txt">hallow</a>

</body>

</html>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326613937&siteId=291194637