xmlhttpを使用して他のページからデータを取得します
ASPコードを書くとき、誰もが投稿または取得を通じてフォームデータを取得できることを誰もが知っています。では、どのようにして他のページで直接データを取得するのでしょうか?これには、XMLHTTPプロトコルの使用が必要です。 XMLHTTPはXMLDOMテクノロジーの一部です。
次のコードは非常に簡単な例です。 XMLHTTPテクノロジーを使用して、http://www.xxxx.com/のホームページのコードをXMLの形式で完全に取得し、ページに出力します。
<%
dimobjxmlhttp、xml
setxml = server.createObject( "microsoft.xmlhttp")
xml.open "get"、 "http://www.codetoad.com/"、false
'Pulthedatafromthewebpage
xml.send
respons.write "here'sthehtmlwenowhaveinourxmlobject"
Response.Write "<br> <br> <br>"
Response.Write "<xmp>"
respons.writexml.responsetext
respons.write "</xmp>"
Response.Write "<br> <br> <br>"
Response.Write「Howhere'here'showthepagelooks:<br> <br>」
respons.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)then
respons.write(objxml.transformnode(objxsl))
それ以外
Response.Write "Error:"&objxsl.parseerror.Reason& "url:"&objxsl.url
endif
setobjhttp =何もない
setobjxml =何もありません
setobjxsl = Nothing
%>
style.xsl:
<xsl:stylesheetxmlns:xsl = "http://www.w3.org/tr/wd-xsl">
<xsl:templatematch = "/">
<html>
<head>
<title>さらに... </title>
</head>
<bodybgcolor = "ffffff">
<divalign = "center">
<tablebgcolor = "ffffff" border = "0" cellpadding = "4" cellspacing = "0" width = "100%">
<xsl:for-eachselect = "moreovernews/article">
<trvalign = "middle">
<tdalign = "left" bgcolor = "ffffff">
<XSL:aTtibutEname = "href">
<xsl:value-ofselect = "url"/>
</xsl:属性>
<XSL:aTtibutEname = "Target">
_空白
</xsl:属性>
<xsl:value-ofselect = "headline_text"/>