로그인

이메일
비밀번호
DaeYoung's Blog : 위치로그 : 태그 : 방명록 : 관리자 : 새글쓰기
XML 응답
Web/Ajax, (2007년 04월 26일 14시 15분)
book.jsp ==============================
<?xml version="1.0" encoding="euc-kr" ?>
<%@ page contentType="text/xml; charset=EUC-KR"%>

<books>
        <book>
                <title>성공적인 웹 프로그....</title>
                <author>아무개</author>
        </book>
        <book>
                <title>웹 프로그....</title>
                <author>무</author>
        </book>
        <book>
                <title>로그....</title>
                <author>개</author>
        </book>0
</books>



httpReq.js=====================================

function getXMLRequest(){
        if(window.ActiveXObject){
                try{
                        //Msxml2.XMLHTTP객첵가 상위버전
                        return new ActiveXObject("Msxml2.XMLHTTP");
                }catch(e){
                        try{
                                //Msxml2.XMLHTTP 실패시 하위버전 객체 선언
                                return new ActiveXObject("Microsoft.XMLHTTP");
                        }catch(e1){
                                return null;
                        }
                }
        }else if(window.XMLHttpRequest){
                return new XMLHttpRequest(); //IE 이외 브라우저
        }else{
                return null;
        }
}

//XMLHttpRequest 객체 구하기
var httpRequest = null ;

function sendRequest(url, params, callback, method){
        httpRequest = getXMLRequest();

        var httpMethod = method?method:'GET';
        if(httpMethod != 'GET' && httpMethod != 'POST'){
                httpMethod = 'GET';
        }
        var httpParams = (params == null || params=='')?null:params;
        var httpUrl = url ;
        if(httpMethod == 'GET' && httpParams != null){
                httpUrl = httpUrl+"?"+httpParams
        }
        httpRequest.open(httpMethod, httpUrl, true);
        httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        httpRequest.onreadystatechange = callback;
        httpRequest.send(httpMethod=='POST'?httpParams:null);
}



view.html=========================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html
 xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<script type="text/javascript" src="httpReq.js"></script>
<script type="text/javascript">
        function loadBooks(){
                sendRequest("book.jsp", null, loadedBooks, "GET");
        }

        function loadedBooks(){
                if(httpRequest.readyState==4){
                        if(httpRequest.status==200){

                                var xmlDoc = httpRequest.responseXML;
                                var bookList = xmlDoc.getElementsByTagName("book");
                                var message = "총 개수 :"+bookList.length+"권\n";

                                for(i=0; i<bookList.length; i++){
                                        var book = bookList.item(i);
                                        var title = book.getElementsByTagName("title").item(0).firstChild.nodeValue;
                                        var author =book.getElementsByTagName("author").item0).firstChild.nodeValue;
                                        message += title+"("+author+")\n";
                                }

                                document.getElementById("here").innerHTML=message ;

                        }
                }
        }
        window.onload=function(){
                loadBooks();
        }

</script>
<title>Insert title here</title>
</head>
<body>
<div id="here"></div>
</body>
</html>


결과 ========================================
총 개수 :3권
성공적인 웹 프로그....(아무개)
웹 프로그....(무)
로그....(개)

http://laedu.net/trackback/7
DaeYoung's Blog 블로그에 오신것을 환영해요^^
웹기반 프로그래밍에 관한 것들을 모을 예정이었는데..
«   2024년 09월   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Javax.mail 참고 사이트.
C# TextBox KeyDown, KeyPr...
SID가 여러개 있을때 'ORA...
https://scrapingmaster.blogg...
https://scrapingmaster.blogg.. 2023년
expertdecoders.com.
expertdecoders.com 2023년
expertdecoders.
expertdecoders 2023년
best decaptcha service.
best decaptcha service 2023년
capcher.
capcher 2023년
24
108
1020394