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
|
function LiveAjaxCall(mode, url)
{
var xml = null;
if (window.XMLHttpRequest) {
xml = new XMLHttpRequest();
if (("xml" == mode) && xml.overrideMimeType)
xml.overrideMimeType('text/xml');
} else if (window.ActiveXObject) {
try {
xml = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xml = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
this.url = url;
this.xml = xml;
this.onerror = function(message) {};
this.oncomplete = function() {};
this.request = function(param, value)
{
var url = this.url;
if (param != "") {
var url = this.url+'?'+param+"="+value;
}
var obj = this;
this.xml.onreadystatechange = function() { obj.readystatechanged(); }
this.xml.open('GET', url, true);
this.xml.send(null);
};
this.readystatechanged = function()
{
try {
if (this.xml.readyState == 4) {
if (this.xml.status == 200) {
if ("xml" == mode) {
var xmldoc = xml.responseXML;
var result = Number(xmldoc.getElementsByTagName('response').item(0).firstChild.data);
if (!result) {
var error = xmldoc.getElementsByTagName('error').item(0).firstChild.data;
this.onerror(error);
} else {
this.oncomplete();
}
} else {
this.oncomplete();
}
} else {
this.onerror('Invocation of webservice "'+this.url+'" failed with http status code '+this.xml.status);
}
}
} catch (e) {
this.onerror('Invocation of webservice "'+this.url+'" failed with exception: '+e.message);
}
};
}
function LiveSimpleAjaxRequest(url, param, value)
{
var xml = new LiveAjaxCall("xml", url);
xml.onerror = function(message) { alert(message); }
xml.request(param, value);
};
|