1 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| var AJAX = function(_call, _method, _synchronous, _response, _wait)
{
if (_method != "GET" && _method != "POST")
{
_method = "GET";
window.alert("Invalid method received (should be GET or POST)");
}
this.call = _call;
this.method = _method;
this.parameters = new Array();
this.numberParameters = 0;
this.object = false;
this.synchronous = _synchronous;
this.divWait = _wait;
this.divResponse = _response;
if (window.XMLHttpRequest)
{
this.object = new XMLHttpRequest();
}
else if (window.ActiveXthis.object)
{
this.object = new ActiveXthis.object("Microsoft.XMLHTTP");
}
else
{
window.alert("Your browser does not support AJAX");
}
this.object.onreadystatechange = this.functionOnChange;
}
AJAX.prototype.toString = function ()
{
return "AJAX Class";
}
AJAX.prototype.functionOnChange = function ()
{
if (this.object.readyState == 4)
{
if (this.object.status == 200)
{
this.divWait.innerHTML = "";
this.divResponse.innerHTML = this.object.responseText;
alert("cas 1");
}
else
{
this.divWait.innerHTML = "Document not found";
alert("cas 2");
}
}
else
{
this.divWait.innerHTML = "Step " + (this.object.readyState + 1) + " / 5<br />Loading, please wait...";
alert("cas 3");
}
}
AJAX.prototype.reset = function ()
{
this.parameters = new Array();
this.numberParameters = 0;
}
AJAX.prototype.addParameter = function (_name, _value)
{
this.parameters[this.numberParameters++] = new Array(_name, escape(_value));
}
AJAX.prototype.loadResponse = function (_event)
{
if (this.method == "GET")
{
realCall = this.call + "?";
for (var i = 0; i < this.numberParameters; i++)
{
realCall += this.parameters[i][0] + "=" + this.parameters[i][1] + "&";
}
realCall = realCall.substr(0, realCall.length - 1);
this.object.open(this.method, realCall, this.synchronous);
this.object.send(null);
}
else
{
this.object.open(this.method, this.call, this.synchronous);
this.object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
realCall = "";
for (var i = 0; i < this.numberParameters; i++)
{
realCall += this.parameters[i][0] + "=" + this.parameters[i][1] + "&";
}
realCall = realCall.substr(0, realCall.length - 1);
this.object.send(realCall);
}
} |
Partager