1
/* Simple AJAX Code-Kit (SACK) v1.6.1 */
2
/* �2005 Gregory Wild-Smith */
3
/* www.twilightuniverse.com */
4
/* Software licenced under a modified X11 licence,
5
see documentation or authors website for more details */
10
this.resetData = function() {
12
this.queryStringSeparator = "?";
13
this.argumentSeparator = "&";
15
this.encodeURIString = true;
18
this.elementObj = null;
19
this.requestFile = file;
20
this.vars = new Object();
21
this.responseStatus = new Array(2);
24
this.resetFunctions = function() {
25
this.onLoading = function() { };
26
this.onLoaded = function() { };
27
this.onInteractive = function() { };
28
this.onCompletion = function() { };
29
this.onError = function() { };
30
this.onFail = function() { };
33
this.reset = function() {
34
this.resetFunctions();
38
this.createAJAX = function() {
40
this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
43
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
50
if (typeof XMLHttpRequest != "undefined") {
51
this.xmlhttp = new XMLHttpRequest();
58
this.setVar = function(name, value){
59
this.vars[name] = Array(value, false);
62
this.encVar = function(name, value, returnvars) {
63
if (true == returnvars) {
64
return Array(encodeURIComponent(name), encodeURIComponent(value));
66
this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
70
this.processURLString = function(string, encode) {
71
encoded = encodeURIComponent(this.argumentSeparator);
72
regexp = new RegExp(this.argumentSeparator + "|" + encoded);
73
varArray = string.split(regexp);
74
for (i = 0; i < varArray.length; i++){
75
urlVars = varArray[i].split("=");
77
this.encVar(urlVars[0], urlVars[1]);
79
this.setVar(urlVars[0], urlVars[1]);
84
this.createURLString = function(urlstring) {
85
if (this.encodeURIString && this.URLString.length) {
86
this.processURLString(this.URLString, true);
90
if (this.URLString.length) {
91
this.URLString += this.argumentSeparator + urlstring;
93
this.URLString = urlstring;
97
// prevents caching of URLString
98
this.setVar("rndval", new Date().getTime());
100
urlstringtemp = new Array();
101
for (key in this.vars) {
102
if (false == this.vars[key][1] && true == this.encodeURIString) {
103
encoded = this.encVar(key, this.vars[key][0], true);
104
delete this.vars[key];
105
this.vars[encoded[0]] = Array(encoded[1], true);
109
urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
112
this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
114
this.URLString += urlstringtemp.join(this.argumentSeparator);
118
this.runResponse = function() {
122
this.runAJAX = function(urlstring) {
126
this.createURLString(urlstring);
128
this.elementObj = document.getElementById(this.element);
132
if (this.method == "GET") {
133
totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
134
this.xmlhttp.open(this.method, totalurlstring, true);
136
this.xmlhttp.open(this.method, this.requestFile, true);
138
this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
142
this.xmlhttp.onreadystatechange = function() {
143
switch (self.xmlhttp.readyState) {
151
self.onInteractive();
154
self.response = self.xmlhttp.responseText;
155
self.responseXML = self.xmlhttp.responseXML;
156
self.responseStatus[0] = self.xmlhttp.status;
157
self.responseStatus[1] = self.xmlhttp.statusText;
163
if (self.elementObj) {
164
elemNodeName = self.elementObj.nodeName;
165
elemNodeName.toLowerCase();
166
if (elemNodeName == "input"
167
|| elemNodeName == "select"
168
|| elemNodeName == "option"
169
|| elemNodeName == "textarea") {
170
self.elementObj.value = self.response;
172
self.elementObj.innerHTML = self.response;
175
if (self.responseStatus[0] == "200") {
186
this.xmlhttp.send(this.URLString);