샘플 예제 > ajax

본문 바로가기
사이트 내 전체검색

ajax

샘플 예제

페이지 정보

작성자 서방님 댓글 1건 조회 397회 작성일 08-08-20 13:37

본문

<SCRIPT LANGUAGE="JavaScript">
<!--
var AJAX = {
        XmlHttp: null,
        create: function () {
                try {
                        if (window.XMLHttpRequest) {
                                AJAX.XmlHttp = new XMLHttpRequest();
                                // 일부의 모질라 버전을은 readyState property,
                                // onreadystate event를 지원하지 않으므로. - from xmlextrs
                                if (this.XmlHttp.readyState == null) {
                                        this.XmlHttp.readyState = 1;
                                        this.XmlHttp.addEventListener("load", function () {
                                            this.XmlHttp.readyState = 4;
                                            if (typeof this.XmlHttp.onreadystatechange == "function")
                                                   tmpXmlHtp.onreadystatechange();
                                        }, false);
                                }
                        } else {
                                AJAX.XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                }
                catch (e) {
                        alert("Your browser does not support XmlHttp objects");
                        //throw new Error("Your browser does not support XmlHttp objects");
                }
        }
}

AJAX.openXML =  function (method, url, async, uname, pswd) {
        if (AJAX.XmlHttp != null) {
                if (uname == undefined) {
                        AJAX.XmlHttp.open(method, url, async, uname, pswd);
                } else {
                        AJAX.XmlHttp.open(method, url, async);
                }
                AJAX.XmlHttp.onreadystatechange = function () {
                        if (AJAX.XmlHttp.readyState == 4) {
                                if (AJAX.XmlHttp.status == 200) {
                                  // 200 은 HTTP에서 성공 i.e) 404 : not found
                                        AJAX.statusSuccessHandler(AJAX.XmlHttp.responseXML.xml);
                                } else {
                                        AJAX.statusErrorHandler();
                                        alert('Error while loading!');
                                }
                        }
                }
        } else {
                alert ("need to create xmlhttp object");
        }
}

AJAX.openText =  function (method, url, async, uname, pswd) {
        if (AJAX.XmlHttp != null) {
                if (uname == undefined) {
                        AJAX.XmlHttp.open(method, url, async, uname, pswd);
                } else {
                        AJAX.XmlHttp.open(method, url, async);
                }
                AJAX.XmlHttp.onreadystatechange = function () {
                        if (AJAX.XmlHttp.readyState == 4) {
                                if (AJAX.XmlHttp.status == 200) {
                                  // 200 은 HTTP에서 성공 i.e) 404 : not found
                                        AJAX.statusSuccessHandler(AJAX.XmlHttp.responseText);
                                } else {
                                        AJAX.statusErrorHandler();
                                        alert('Error while loading!');
                                }
                        }
                }
        } else {
                alert ("need to create xmlhttp object");
        }
}

AJAX.send = function (content) {
                if (content == undefined)
                        AJAX.XmlHttp.send(null);
                else
                        AJAX.XmlHttp.send(content);
}

AJAX.setOnReadyStateChange = function (funcname) {
                if (AJAX.XmlHttp) {
                        AJAX.XmlHttp.onreadystatechange = funcname;
                } else {
                        alert ("need to create xmlhttp object");
                }
}

// status 200 일 때 처리 함수
AJAX.statusSuccessHandler = function (data) {
                alert(data);
}

AJAX.setStatusSuccessHandler = function (funcname) {
                AJAX.statusSuccessHandler = funcname;
}

        // status 200 일 때 기본 처리 함수
        // setStatusSuccessHandler() 로 대체 가능
AJAX.statusErrorHandler = function (status) {
                AJAX.rtnText = AJAX.XmlHttp.responseText;
}

AJAX.setStatusSuccessHandler = function (funcname) {
                AJAX.statusSuccessHandler = funcname
}

AJAX.setStatusErrorHandler = function (funcname) {
                AJAX.statusErrorHandler = funcname
}

AJAX.setRequestHeader = function (label, value)
{
        AJAX.XmlHttp.setRequestHeader(label, value);
}

// 사용법
//        AJAX.create();
//        AJAX.openText('GET','jsontest.php', true);
//        AJAX.setStatusSuccessHandler(proc);
//        AJAX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//        AJAX.send("test=테스트");
//
//        function proc(abc)
//        {
//                document.getElementById('test').innerHTML = abc;
//        }

//-->
</SCRIPT>

댓글목록

등록된 댓글이 없습니다.

Total 17건 1 페이지
ajax 목록
번호 제목 글쓴이 조회 날짜
17 서방님 333 04-12
열람중
샘플 예제 댓글+ 1
서방님 398 08-20
15 서방님 392 07-02
14 서방님 324 07-02
13 서방님 396 07-02
12 서방님 350 07-02
11 서방님 215 06-27
10 서방님 201 06-27
9
AJAX 강좌 댓글+ 1
서방님 167 06-12
8 서방님 160 06-12
7
ajax url 댓글+ 1
서방님 152 03-29
6 서방님 153 03-20
5 서방님 153 11-03
4 서방님 160 11-03
3 서방님 151 09-25
게시물 검색

회원로그인

접속자집계

오늘
16
어제
51
최대
1,347
전체
153,646
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.