• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>XML XMLHttpRequest</title>
7
    <script>
8
        function loadDoc() {
9
            var xmlHttp = new XMLHttpRequest();         // XMLHttpRequest 객체를 생성함.
10
            xmlHttp.onreadystatechange = function() {   // onreadystatechange 이벤트 핸들러를 작성함.
11
                // 서버상에 문서가 존재하고 요청한 데이터의 처리가 완료되어 응답할 준비가 완료되었을 때
12
                if(this.status == 200 && this.readyState == this.DONE) {
13
                    // 요청한 데이터를 문자열로 반환함.
14
                    document.getElementById("text").innerHTML = xmlHttp.responseText;
15
                }
16
            };
17
            xmlHttp.open("GET", "/examples/media/xml_httpxmlrequest_data.txt", true);
18
            xmlHttp.send();
19
        }
20
    </script>
21
</head>
22
​
23
<body>
24
​
25
    <h1>XMLHttpRequest 객체의 전송</h1>
26
    <button onclick="loadDoc()">요청 전송하기!</button>
27
    <p id="text"></p>
28
    
29
</body>
30
​
31
</html>