1
var net=new Object();
2
net.READY_STATE_UNINITIALIZED=0;
3
net.READY_STATE_LOADING=1;
4
net.READY_STATE_LOADED=2;
5
net.READY_STATE_INTERACTIVE=3;
6
net.READY_STATE_COMPLETE=4;
7
net.ContentLoader=function(url,onload,onerror)
{
8
this.url=url;
9
this.req=null;
10
this.onload=onload;
11
this.onerror=(onerror) ? onerror : this.defaultError;
12
this.loadXMLDoc(url);
13
}
14
net.ContentLoader.prototype=
{
15
loadXMLDoc:function(url)
{
16
if (window.XMLHttpRequest)
{
17
this.req=new XMLHttpRequest();
18
} else if (window.ActiveXObject)
{
19
this.req=new ActiveXObject("Microsoft.XMLHTTP");
20
}
21
if (this.req)
{
22
try
{
23
var loader=this;
24
this.req.onreadystatechange=function()
{
25
loader.onReadyState.call(loader);
26
}
27
this.req.open('GET',url,true);
28
this.req.send(null);
29
}catch (err)
{
30
this.onerror.call(this);
31
}
32
}
33
},
34
onReadyState:function()
{
35
var req=this.req;
36
var ready=req.readyState;
37
if (ready==net.READY_STATE_COMPLETE)
{
38
var httpStatus=req.status;
39
if (httpStatus==200 || httpStatus==0)
{
40
this.onload.call(this);
41
}else
{
42
this.onerror.call(this);
43
}
44
}
45
},
46
defaultError:function()
{
47
alert("error fetching data!"
48
+"\n\nreadyState:"+this.req.readyState
49
+"\nstatus: "+this.req.status
50
+"\nheaders: "+this.req.getAllResponseHeaders());
51
}
52
}

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
