`

innerHTML.html

阅读更多
例子来源:《Ajax 基础教程》 金灵 等译 这本书非常不错

<html>
<head>
<title>Using responseText with innerHTML</title>
<script>
var xmlHttp;
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}
function startRequest() {
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", "innerHTML.xml", true);
	xmlHttp.send(null);
}
function handleStateChange() {
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			document.getElementById("results").innerHTML = xmlHttp.responseText;
		}
	}
}
</script>
</head>
<body>
<form action="#">
	<input type="button" value="Serrch for Today's Activeties" onClick="startRequest();">
</form>
<div id="results"></div>
</body>
</html>


innerHTML.xml

<table border="1">
	<tbody>
		<tr>
			<th>Activity Name</th>
			<th>Location</th>
			<th>Time</th>
		</tr>
		<tr>
			<td>Waterskiing</td>
			<td>Dock #1</td>
			<td>9:00 AM</td>
		</tr>
		<tr>
			<td>Volleyball</td>
			<td>East Court</td>
			<td>2:00 PM</td>
		</tr>
		<tr>
			<td>Hiking</td>
			<td>Trail 3</td>
			<td>3:30 PM</td>
		</tr>
	</tbody>
</table>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics