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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/**************************************************
* Initialisation code for our xmlhttp object
* which is used to request URLs within javascript
**************************************************/
function createXmlHttp()
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
}
catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
function XmlHttpGet()
{
var xmlhttp = createXmlHttp();
if (xmlhttp) {
function xmlhttpwrapper(xmlhttp) {
this.xmlhttp = xmlhttp;
this.get = function(url, params) {
var contentdata = "";
for (var key in params)
{
var value = params[key];
if (contentdata) contentdata += "&";
contentdata += key + "=" + value;
}
// WARNING: if the URL is too long this will fail
if (url.search("\\?") == -1)
url += "?";
url += contentdata;
this.xmlhttp.open("GET", url);
this.send();
}
this.open = function(method, url) { this.url = url; this.xmlhttp.open(method, url); },
this.send = function() {
var parent = this;
this.xmlhttp.onreadystatechange = function() { parent.onreadystatechange()} ;
this.xmlhttp.send(""); },
this.onreadystatechange = function() {
if (this.xmlhttp.readyState == 4)
{
// if (this.xmlhttp.status == "200") {
if (this.responsehandler) {
var response = this.xmlhttp.responseText;
this.responsehandler(response);
}
else if (this.xmlresponsehandler) {
var xmlresponse = this.xmlhttp.responseXML;
this.xmlresponsehandler(xmlresponse);
}
// }
}
}
}
return new xmlhttpwrapper(xmlhttp);
}
return xmlhttp;
}
function PostXmlHttp()
{
var xmlhttp = createXmlHttp();
if (xmlhttp) {
function xmlhttpwrapper(xmlhttp) {
this.xmlhttp = xmlhttp;
this.post = function(url, params) {
this.xmlhttp.open("POST", url);
this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
var contentdata = "";
for (var key in params)
{
var value = params[key];
if (contentdata) contentdata += "&";
contentdata += key + "=" + value;
}
this.send(contentdata);
}
this.open = function(method, url) { this.url = url; this.xmlhttp.open(method, url); },
this.send = function(content) {
var parent = this;
this.xmlhttp.onreadystatechange = function() { parent.onreadystatechange()} ;
this.xmlhttp.send(content); },
this.onreadystatechange = function() {
if (this.xmlhttp.readyState == 4)
{
if (this.xmlhttp.status == "200") {
if (this.responsehandler) {
var response = this.xmlhttp.responseText;
this.responsehandler(response);
}
else if (this.xmlresponsehandler) {
var xmlresponse = this.xmlhttp.responseXML;
this.xmlresponsehandler(xmlresponse);
}
}
}
}
}
return new xmlhttpwrapper(xmlhttp);
}
return xmlhttp;
}
|