2 // Cross browser ajax upload class
4 var my_AJAX
= new function (){
5 var cache
= new Array();
7 // Cross browser ajax object creation
9 this.getXmlHttp = function (){
11 if (typeof XMLHttpRequest
!= "undefined")
12 xmlhttp
= new XMLHttpRequest();
13 if (xmlhttp
) return xmlhttp
;
15 xmlhttp
= new ActiveXObject("Msxml2.XMLHTTP");
18 xmlhttp
= new ActiveXObject("Microsoft.XMLHTTP");
26 this.upload = function(mode
, url
, oncomplete
) {
27 if (this.isCached(url
)){
28 oncomplete(this.getCache(url
));
31 var ajax
= this.getXmlHttp();
38 ajax
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
42 ajax
.onreadystatechange = function() {
43 switch (ajax
.readyState
) {
48 self
.addCache(ajax
.responseText
, url
);
49 ajax
.onreadystatechange = function() {};
50 oncomplete(ajax
.responseText
);
57 this.GETupload = function(url
, oncomplete
) {
58 this.upload('GET', url
, oncomplete
);
60 this.POSTupload = function(url
, oncomplete
) {
61 this.upload('POST', url
, oncomplete
);
66 this.addCache = function(text
, key
) {
69 this.getCache = function(key
) {
72 this.isCached = function(url
) {
73 return cache
[url
] ? true : false;
78 // HTML added in innerHTML can contain java script code
79 // Need upload it and use
80 var scr_includes
= new Array();
81 function execHTMLScripts(node
)
83 parseScript(node
.getElementsByTagName('script'), 0);
85 function parseScript(list
, n
)
89 var script
= list
[n
++];
90 var id
= script
.src
? script
.src
: script
.id
;
91 if (id
&& !scr_includes
[id
])
93 scr_includes
[id
] = true;
94 var s
= document
.createElement('script');
95 document
.getElementsByTagName('head')[0].appendChild(s
);
98 // in IE onload event not work, but work onreadystatechange
100 s
.onload = function(){this.onload
= this.onreadystatechange = function(){}; parseScript(list
, n
);}
101 s
.onreadystatechange = function(){if (this.readyState
== 'loaded' || this.readyState
== 'complete') this.onload();}
108 parseScript(list
, n
);