XMLHttpRequest
.function Hijax() {
var container,url,canvas,data,loading,callback,request;
this.setContainer = function(value) {
container = value;
};
this.setUrl = function(value) {
url = value;
};
this.setCanvas...
this.setLoading...
this.setCallback...
}
this.captureData = function() {
if (container.nodeName.toLowerCase() == "form" {
container.onsubmit = function() {
var query = "";
for (var i=0; i<this.elements.length; i++) {
query+= this.elements[i].name;
query+= "=";
query+= escape(this.elements[i].value);
query+= "&";
}
data = query;
return !start();
};
} else {
var links = container.getElementsByTagName("a");
for (var i=0; i<links.length; i++) {
links[i].onclick = function() {
var query = this.getAttribute("href").split("?")[1];
url+= "?"+query;
return !start();
};
}
links = null;
}
var start = function() {
request = getHTTPObject();
if (!request || !url) {
return false;
} else {
initiateRequest();
return true;
}
};
var initiateRequest = function() {
if (loading) {
loading();
}
request.onreadystatechange = completeRequest;
if (data) {
request.open("POST", url, true);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send(data);
} else {
request.open("GET", url, true);
request.send(null);
}
};
var completeRequest = function() {
if (request.readyState == 4) {
if (request.status == 200 || request.status == 304) {
if (canvas) {
canvas.innerHTML = request.responseText;
}
if (callback) {
callback();
}
}
}
};
function Hijax() {
this.setContainer = function(value) { };
this.setUrl = function(value) { };
this.setCanvas = function(value) { };
this.setLoading = function(value) { };
this.setCallback = function(value) { };
this.captureData = function() { };
}
function Hijax() {
var start = function() { };
var getHTTPObject = function() { };
var initiateRequest = function() { };
var completeRequest = function() { };
}
var instance = new Hijax();
instance.setContainer(document.getElementById("container"));
instance.setUrl("myfile.php");
instance.setCanvas(document.getElementById("canvas"));
instance..setLoading(function() {
displayLoading(document.getElementById("canvas"));
});
instance.setCallback(function() {
fadeUp(document.getElementById("canvas");
});
instance.captureData();
var container,url,canvas,data,loading,callback,errorhandler,request;
this.setErrorhandler = function(value) {
errorhandler = value;
};
if (request.status == 200 || request.status == 304) {
...
} else {
if (errorhandler) {
errorhandler();
}
}
var container,url,canvas,data,loading,callback,errorhandler,request,timer;
timer = setTimeout(function() {
request.onreadystatechange = function() {};
request.abort();
if (errorhandler) {
errorhandler();
}
},60000);
if (request.status == 200 || request.status == 304) {
clearTimeout(timer);
}