get real!

cooljohn.egloos.com

포토로그



XMLHTTP basic programming

<script language='JavaScript'>

// initial invoking
function initiate()
{

    var urlVar = "#";        //[some url to return the result]
    // this url should be encoded as below
    // Response.Charset="euc-kr"
    // or
    //  <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
    // For XMLHTTP returns unicode result.

    createXMLHTTP(urlVar);

}

function createXMLHTTP(_urlValue)
{
    var pageURL = _urlValue;
    var xmlRequest;
    if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
        try {
            xmlRequest = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e){
            try{
                xmlRequest = new ActiveXObject("Microsoft.XMLHTTP")
            }
        catch (e){}
        }
    }
    else if (window.XMLHttpRequest) // if Mozilla, Safari etc
        xmlRequest = new XMLHttpRequest()
    else
        return false

    xmlRequest.Open("POST", pageURL, true);
    xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    xmlRequest.onreadystatechange = function() {CallBack(xmlRequest)};
    xmlRequest.Send(null);

    return xmlRequest;
}

function CallBack(xmlRequest)
{
    if (xmlRequest == null || xmlRequest.readyState != 4) return;

    //--- Do next process according to xmlRequest.responseText
    doNextUpToTheResult(xmlRequest.responseText);

}



function doNextUpToTheResult(val)
{
    if (val=="case1")
    {
        alert("doing something....for case 1");
    }else
    {
        if (val=="case2")
        {
            alert("doing something....for case 2");
        }else
        {
            alert("doing nothing...");
        }
    }
}
</script>


//--- sample of URL for the result
<%
Response.Charset="euc-kr"

'response.write "aoeCode1^aoeName1"
response.write "aoeCode2^aoeName2"
%>

덧글

댓글 입력 영역