I'm having a small issue with the following code. The text variable is coming up undefined when returning the ajax responseText. The alert(response); gives me what is in the echo.txt file but return doesn't seem to be working.

PHP Code:
var text ajax({
        
'url' 'echo.txt'
    
});

alert(text); 
PHP Code:
function ajax(params)
{
    var 
args = { 'method' 'GET''url' 'echo.txt''async' true }
            
    if (
params)
    {
        for (var 
index in args) { if (typeof params[index] != 'undefined'args[index] = params[index]; }
    }
            
    var 
http;
    if (
window.XMLHttpRequest) { http = new XMLHttpRequest(); }
    else { 
http = new ActiveXObject('Microsoft.XMLHTTP'); }
            
    
http.onreadystatechange = function()
    {
        if (
http.readyState == 4)
        {
            var 
response http.responseText;
            
alert(response);
            return 
response;
        }
    }
            
    
http.open(args['method'], args['url'], args['async']);
    
http.send();

Any help is appreciated.