รับข้อมูลจากหน้าอื่น ๆ โดยใช้ 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
'Pullthedatafromthewebpage
xml.send
Response.write "Here'Sthehtmlwenowhaveinourxmlobject"
Response.write "<br> <br> <br>"
Response.write "<xmp>"
response.writexml.responsetext
Response.write "</xmp>"
Response.write "<br> <br> <br>"
Response.write "ไม่มีที่ไหนเลย
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"
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>
<head>
<title> ยิ่งไปกว่านั้น ... </title>
</head>
<bodybgcolor = "ffffff">
<divalign = "center">
<tableBgColor = "ffffff" border = "0" cellpadding = "4" cellspacing = "0" width = "100%">
<xsl: for-eCeSelect = "ยิ่งกว่านั้น/บทความ">
<trvalign = "กลาง">
<tdalign = "ซ้าย" bgcolor = "ffffff">
<xsl: attributeName = "href">
<xsl: value-ofselect = "url"/>
</xsl: แอตทริบิวต์>
<xsl: attributeName = "เป้าหมาย">
_ว่างเปล่า
</xsl: แอตทริบิวต์>
<xsl: value-oflect = "Headline_text"/>