• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>Ajax jQuery</title>
7
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
8
    <script>
9
        $(function() {
10
            $("#requestBtn").on("click", function() {
11
                // POST 방식으로 서버에 HTTP 요청을 보냄.
12
                $.post("/examples/media/request_ajax.php", 
13
                    { name: "이순신", grade: "A+" },   // 서버가 필요한 정보를 같이 보냄.
14
                    function(data, status) {
15
                        $("#text").html(data + "<br>" + status);    // 전송받은 데이터와 전송 성공 여부를 보여줌.
16
                    }
17
                );
18
            });
19
        });
20
    </script>
21
</head>
22
​
23
<body>
24
​
25
    <h1>$.post() 메소드</h1>
26
    <button id="requestBtn">POST 방식으로 데이터 불러오기!</button>
27
    <p id="text"></p>
28
    
29
</body>
30
​
31
</html>