To make your code work you can use closures and pass functions as parameters.
2 properties javascript is very good at.
snappyajaxfunction(url, fn)
{
var request...
request.onreadystatechange=function()
{
if (request.readyState==4)
{
fn(request.responseText);
}
};
request.open("GET",url,true);
request.send(null);
}
to use it you can build a function like
var doSomething = function(response){
alert(response);
};
snappyajaxfunction('/country/code/32', doSomething);
The closure allows 'request' to be available within the function that handles the onreadystatechange.
The function 'fn' is passed as a parameter of snappyajaxfunction.