AJAX Sample
서버의 파일(ajax_info.txt)을 가져와서 데이터폼을 TXT를 바꿔주는 샘플.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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">
function loadXMLDoc() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET", "ajax_info.txt", false);
xmlhttp.send();
}
</script>
</head>
<body>
<div id = "myDiv"> <h2> Let AJAX change this text</h2></div>
<button type = "button" onclick = "loadXMLDoc()">Change Content</button>
</body>
</html>