티스토리 뷰

프로그래밍

[JAVASCRIPT] XDomainRequest

ReturnToHome 2016. 12. 24. 21:05

** getXMLHttpRequest() 메소드 참고

 

 

function getXMLHttpRequest(){

    if (window.XDomainRequest) { // IE 8, 9, 10

        try {

            return new XDomainRequest();

        } catch(e) {

            try {

                return new ActiveXObject("Msxml2.XMLHTTP");

            } catch(e) {

                try {

                    return new ActiveXObject("Microsoft.XMLHTTP");

                } catch(e1) {

                    return null;

                }

            }

        }

    } else if (window.ActiveXObject) { // IE 5, 6, 7

        try {

            return new ActiveXObject("Msxml2.XMLHTTP");

        } catch(e) {

            try {

                return new ActiveXObject("Microsoft.XMLHTTP");

            } catch(e1) {

                return null;

            }

        }

    } else if (window.XMLHttpRequest) { // Other

        return new XMLHttpRequest();

    } else {

        return null;

    }

}

 

 

var xdr = getXMLHttpRequest();

 

if (window.XDomainRequest) {

    xdr.open('get', 'http://cross.domain.com');

    xdr.withCredentials = true;

    xdr.onload = function() {

        var result = xdr.responseText;

    

        console.log(result);

    };

 

    // POST 보낼 시 xdr.send([DATA]), GET 일시 xdr.send() or xdr.send('')

    setTimeout(function () {xdr.send();}, 0);

 

} else {

    // TODO Another Method

}

'프로그래밍' 카테고리의 다른 글

[DB] Nested Loop / Merge / Hash  (0) 2016.12.24
[JAVA] ArrayList to Array, Array to ArrayList  (0) 2016.12.24
[DB] IBATIS 동적 SQL 요소.  (0) 2016.12.24
[ETC] Eclipse Java Decompiler  (0) 2016.12.24
[DB] ORACLE 채번 함수 만들기  (0) 2016.12.24
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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 31
글 보관함