I’m having a small issue with the following code. The text variable is coming up [I]undefined [I]responseText[I]alert(response);[I]echo.txt
[code=php]
var text = ajax({
‘url’ : ‘echo.txt’
});
alert(text);
[code=php]
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.