mirror of
https://github.com/2009scape/2009scape.github.io.git
synced 2024-11-20 01:42:41 +01:00
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
|
|
||
|
|
||
|
function ajax_debug(text) {
|
||
|
if(document.getElementById("javascript-debug-pane")) document.getElementById("javascript-debug-pane").value+=text + "\n";
|
||
|
}
|
||
|
function httpRequest() {
|
||
|
// Create the requestHandler
|
||
|
try {
|
||
|
this.requestHandler=new ActiveXObject("Msxml2.XMLHTTP");
|
||
|
}
|
||
|
catch(e1) {
|
||
|
try {
|
||
|
this.requestHandler=new ActiveXObject("Microsoft.XMLHTTP");
|
||
|
}
|
||
|
catch(e2) {
|
||
|
this.requestHandler=false;
|
||
|
}
|
||
|
}
|
||
|
if(!this.requestHandler && window.createRequest) {
|
||
|
try {
|
||
|
this.requestHandler=window.createRequest();
|
||
|
}
|
||
|
catch(e) {
|
||
|
this.requestHandler=false;
|
||
|
}
|
||
|
}
|
||
|
if(!this.requestHandler && typeof(XMLHttpRequest)!='undefined') {
|
||
|
try {
|
||
|
this.requestHandler=new XMLHttpRequest();
|
||
|
}
|
||
|
catch(e) {
|
||
|
this.requestHandler=false;
|
||
|
}
|
||
|
}
|
||
|
ajax_debug("New httpRequest created");
|
||
|
}
|
||
|
httpRequest.prototype.handleChange=function() {
|
||
|
//ajax_debug("ReadyState changed to " + this.requestHandler.readyState);
|
||
|
if(this.requestHandler.readyState==4 && this.callback) this.callback(this.requestHandler.responseText);
|
||
|
}
|
||
|
httpRequest.prototype.get=function(url, callback) {
|
||
|
ajax_debug("GET " + url + (callback==null ? " (no callback)" : " (with callback)"));
|
||
|
var copy=this;
|
||
|
this.requestHandler.onreadystatechange=function() {copy.handleChange();}
|
||
|
if(callback) this.callback=callback;
|
||
|
else this.callback=null;
|
||
|
this.requestHandler.open("GET", url, true);
|
||
|
this.requestHandler.send(null);
|
||
|
}
|
||
|
function ajax_describe(what) {
|
||
|
a="";
|
||
|
for(part in what) try{a+=part + "=" + what[part] + "\n";} catch(e) {}
|
||
|
return a;
|
||
|
}
|
||
|
function throwaway_request(url) {
|
||
|
var req=new httpRequest();
|
||
|
req.get(url);
|
||
|
}
|
||
|
function callback_request(url, callback) {
|
||
|
var req=new httpRequest();
|
||
|
req.get(url, callback);
|
||
|
}
|