View Full Version : AJAX 'undefined' return in IE, please help!

11-06-2007, 04:39 PM
I hope somebody can tell me why this is happening...

I'm calling the following:

var raw_css = request_lite('?page=get_css', returnData);

When I check the value of 'response1' inside the 'request_lite' function, it is correct, but when it is returned to the 'raw_css' variable it is 'undefined'.

This only occurs in Internet Explorer, obviously. Somebody please help!!

function request_lite(url, writeFunction, div)
if (ajax)
// Navigate the application window
var response;
var response1;
ajax.open('get', 'switchboard.php' + url);
ajax.onreadystatechange = function ()
if ((ajax.readyState == 4) && (ajax.status == 200))
response = writeFunction(ajax, div);
response = String(response);
if (response != undefined && response != 'undefined')
response1 = response;
return response1;

// Function used by request_page() to write to the specified div
function writeDiv(ajax, div)
document.getElementById(div).innerHTML = ajax.responseText;

// Function used by request_page() to pass info to array
function returnData(ajax, nothing)
var response = ajax.responseText;
return response;

11-06-2007, 04:55 PM
302 (page unchanged) is also a valid return status

you also have 2 different names for the write function you have
writeDiv and writeFunction

and rather then checking if its undefined, check if its null


11-06-2007, 05:36 PM
Thank you for responding so quickly boogeyman.

Unfortunately, it seems a bit more complicated than that. If you were to put 'alert(response1)' right before the line 'return response1' in the 'request_lite' function, you would get the ajax response.

If you were to check the exact same value outside the function it will give 'undefined'.

For some reason, the value is undefined when it passes through the return.

Again, this is only in IE.