This is not bulletproof and just to give you an example.
function ajax(url, callback) {
var req = new XMLHttpRequest();
req.open("GET", url, true);
req.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
if(callback)
{
callback(this.responseText);
}
}
};
req.send();
}
as a wrapper, so you end up doing something like
function loadIndex()
{
ajax('/', function(data){
alert(data);
loadIndexAgain();
});
}
function loadIndexAgain()
{
ajax('/', function(data){
alert('more stuff happened');
});
}
loadIndex();
and your statements will be chained.
fiddle.