案例:XML 实例     状态:不可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
var xmlhttp
5
6
function loadXMLDoc(url)
7
{
8
xmlhttp=null
9
// code for Mozilla, etc.
10
if (window.XMLHttpRequest)
11
  {
12
  xmlhttp=new XMLHttpRequest()
13
  }
14
// code for IE
15
else if (window.ActiveXObject)
16
  {
17
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
18
  }
19
if (xmlhttp!=null)
20
  {
21
  xmlhttp.onreadystatechange=state_Change
22
  xmlhttp.open("GET",url,true)
23
  xmlhttp.send(null)
24
  }
25
else
26
  {
27
  alert("Your browser does not support XMLHTTP.")
28
  }
29
}
30
31
function state_Change()
32
{
33
// if xmlhttp shows "loaded"
34
if (xmlhttp.readyState==4)
35
  {
36
  // if "OK"
37
  if (xmlhttp.status==200)
38
  {
39
  alert("XML data OK")
40
  document.getElementById('A1').innerHTML=xmlhttp.status
41
  document.getElementById('A2').innerHTML=xmlhttp.statusText
42
  document.getElementById('A3').innerHTML=xmlhttp.responseText
43
  }
44
  else
45
  {
46
  alert("Problem retrieving XML data:" + xmlhttp.statusText)
47
  }
48
  }