XMLHTTP를 사용하여 다른 페이지에서 데이터를 가져옵니다
우리가 ASP 코드를 작성할 때, 모든 사람은 게시물 또는 get을 통해 양식 데이터를 얻을 수 있다는 것을 알고 있습니다. 그렇다면 다른 페이지에서 데이터를 어떻게 직접 얻습니까? XMLHTTP 프로토콜을 사용해야합니다. XMLHTTP는 XMLDOM 기술의 일부입니다.
다음 코드는 매우 간단한 예입니다. XMLHTTP 기술을 사용하여 XML 형식으로 http://www.xxxx.com/의 홈 페이지에서 코드를 완전히 얻고 페이지에서 출력합니다.
<%
dimobjxmlhttp, xml
setxml = server.createobject ( "microsoft.xmlhttp")
xml.open "get", "http://www.codetoad.com/", false
'The PulltheDataThewebpage
xml.send
response.write "here'sthehtmlwenowhaveinourxmlobject"
응답. "<br> <br> <br>"
response.write "<xmp>"
response.writexml.responsetext
응답. "</xmp>"
응답. "<br> <br> <br>"
response.write "nowle'showthepagelooks : <br> <br>"
response.writexml.responsetext
setxml = 아무것도 없습니다
%>
다음은 또 다른 예입니다
<%
dimobjhttp, objxml, objxsl
setobjhttp = server.createobject ( "microsoft.xmlhttp")
objhttp.open "get", "http://p.moreover.com/cgi-local/page?c=pop%20Music%20reviews&o=xml", false
objhttp.send
setobjxml = objhttp.responsexml
setobjxsl = server.createobject ( "microsoft.xmldom")
objxsl.async = false
objxsl.load (server.mappath ( "style.xsl"))
if (objxsl.parseerror.errorcode = 0)
response.write (objxml.transformNode (OBJXSL))
또 다른
response.write "오류 :"& objxsl.parseerror.reason & "url :"& objxsl.url
endif
setobjhttp = 아무것도 없습니다
setobjxml = 아무것도 없습니다
setobjxsl = 아무것도 없습니다
%>
style.xsl :
<xsl : stylesheetxmlns : xsl = "http://www.w3.org/tr/wd-xsl">
<xsl : templatematch = "/">
<html>
<헤드>
<title> 또한 ... </title>
</head>
<bodybgcolor = "ffffff">
<divalign = "Center">
<tablebgcolor = "ffffff"border = "0"CellPadding = "4"CellSpacing = "0"width = "100%">
<xsl : for-eachselect = "Morevoynews/Article">
<trvalign = "Middle">
<tdalign = "왼쪽"bgcolor = "ffffff">
<xsl : attributeName = "href">
<xsl : value-ofSelect = "url"/>
</xsl : 속성>
<xsl : attributeName = "target">
_공백
</xsl : 속성>
<xsl : value-ofSelect = "Headline_Text"/>