1
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
2
3
<!
DOCTYPE html PUBLIC
"
-//W3C//DTD XHTML 1.0 Transitional//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"
>
4
5
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
6
<
head runat
=
"
server
"
>
7
<
title
>
XmlHttplObject对象学习第一天
</
title
>
8
<
script language
=
"
javascript
"
type
=
"
text/javascript
"
>
9
var xmlhttp;
10
11
//
创建XMLHttp对象
12
function CreateXmlHttpObject()
13
{
14
if(window.ActiveXObject)
15
{
16
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
17
}
18
else
19
{
20
if(window.XMLHttpRequest)
21
{
22
xmlhttp = new XMLHttpRequest();
23
}
24
}
25
}
26
27
function StartOperate()
28
{
29
CreateXmlHttpObject();
30
xmlhttp.onreadystatechange = Read;
31
xmlhttp.open("Get","XMLFile.xml",true);
32
xmlhttp.send();
33
}
34
function Read()
35
{
36
if(xmlhttp.readystate == 4)
37
{
38
if(xmlhttp.status == 200)
39
{
40
document.getElementById("div_Info").innerHTML = xmlhttp.ResponseText;
41
}
42
}
43
}
44
</
script
>
45
</
head
>
46
<
body
>
47
<
form id
=
"
form1
"
runat
=
"
server
"
>
48
这里没有开始异步调用
49
<
br
/>
50
<
br
/>
51
<
div id
=
"
div_Info
"
>
52
53
</
div
>
54
<
input type
=
"
button
"
id
=
"
button1
"
value
=
"
异步调用
"
onclick
=
"
StartOperate()
"
/>
55
</
form
>
56
</
body
>
57
</
html
>
58

2

3

4

5

6

7

8

9

10

11

12

13



14

15



16

17

18

19



20

21



22

23

24

25

26

27

28



29

30

31

32

33

34

35



36

37



38

39



40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

把一个写xml文件中的内容写到 id为"div_Info"层里
达到了页面不需回发到服务器!