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