//XMLHttpRequest 객체생성
var oXmlHTTP = getXmlHttp();
if (window.XMLHttpRequest)
{
oXmlHttp = new XMLHttpRequest();
}else{
oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
oXmlHTTP.open("POST", "AJAX.asp", false); // 동기방식으로 연결
//리퀘스트 내용을 XML문자열로 만든다. ASP는 기본적으로 EUC-KR로 처리하기 때문에 따로 정의할필요는 없습니다.
//한글을 전송할때는 태그내용을 <![CDATA[ ]]>로 선언해야 합니다.
var strXML = "";
strXML = strXML + "<gwinaemi>";
strXML = strXML + "<strList><![CDATA[내용]]></strList>";
strXML = strXML + "</gwinaemi>";
//리퀘스트 전송
oXmlHTTP.send(strXML);
//받아온 XML문자열에서 에서 strList태그의 내용을 추출 viewText객체의 innerHTML 로 넣는다.
eId("viewText").innerHTML = oResXML.getElementsByTagName("strList").item(0).firstChild.nodeValue;
--------------------------------------------------------------------------------------------------------------
'''''AJAX.asp파일쪽의 처리
'''''받아온 XML문자열을 Request.BinaryRead로 읽어서
'''''microsoft.xmldom 파서로 읽어 Scripting.Dictionary객체로 반환
'''''필요한 리퀘스트 내용은 딕셔너리에서 호출한다.
Dim vntPostedData, lngCount
lngCount = Request.TotalBytes
vntPostedData = Request.BinaryRead(lngCount)
Dim oXMLDom
Set oXMLDom = Server.CreateObject("microsoft.xmldom")
oXMLDom.load(vntPostedData)
Dim oDicXMLRequest
set oDicXMLRequest = Server.CreateObject("Scripting.Dictionary")
If oXMLDom.parseError = 0 Then
Dim objNode
Set objNode = oXMLDom.documentElement
set oXMLDom = nothing
Dim i
For i = 0 To objNode.childNodes.length - 1
oDicXMLRequest.Add objNode.childNodes.Item(i).nodeName, objNode.childNodes.Item(i).Text
Next
set objNode = nothing
else
set oXMLDom = nothing
End if
Response.ContentType = "text/xml"
Response.Charset = "ks_c_5601-1987"
''''''''''''''''XML문서의 형태로 돌려보낸다. encoding을 ASP의 기본엔코딩인 ks_c_5601-1987로 지정한다.
Response.write "<?xml version=""1.0"" encoding=""ks_c_5601-1987""?>" & chr(13) & chr(10)
''''''''''''''''oDicXMLRequest에서 strList의 내용을 불러낸다.
Response.write "<gwinaemi><strList><![CDATA[" & oDicXMLRequest("strList") & "]]></strList></gwinaemi>"
[출처] asp에서 XML파서를 이용한 ajax 한글 처리 방법[펌]|작성자 스톤콜드
보너스.----------------------------------------------------------------------------
'*************************************
'* XML 긁어오기 시작!!
'*************************************
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
objXmlHttp.open "POST", "http://www.abc.com/text_xml.asp?event_kind="&event_kind&"&user_id="&user_id&"&user_key="&user_key&"&gift_kind="&gift_kind, false
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXmlHttp.send '요청
strResponseText = objXmlHttp.responseText '응답 텍스트 저장
Set objXmlHttp = Nothing
'DOM 파서를 이용해 파싱
Set objMsXmlDom = Server.CreateObject("microsoft.XMLDOM")
objMsXmlDom.async = false
objMsXmlDom.loadXML( strResponseText ) '스트링으로 로드하기 때문에 loadXML 메서드 사용.
'데이터 추출.
referResult = ""& Trim( objMsXmlDom.getElementsByTagName("referResult").Item(0).Text )
message = ""& Trim( objMsXmlDom.getElementsByTagName("message").Item(0).Text )
Set objMsXmlDom = Nothing
'*************************************
'* XML 긁어오기 끝!!
'*************************************
function hrefMark(){ }
'Development > Visual Basic | VBScript | ASP' 카테고리의 다른 글
ADO Command 객체중 리턴값을 반환할때 (0) | 2013.05.30 |
---|---|
서버사이드 비동기 접근 (0) | 2013.05.30 |
XMLHTTP (0) | 2013.05.30 |
MSXML2.ServerXMLHTTP (0) | 2013.05.30 |
ASP Dictionary Object (0) | 2012.10.17 |
댓글