Results 1 to 3 of 3

Thread: AJAX 'undefined' return in IE, please help!

  1. #1
    Join Date
    Nov 2007
    Location
    Panama
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default AJAX 'undefined' return in IE, please help!

    I hope somebody can tell me why this is happening...

    I'm calling the following:

    Code:
    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!!
    Code:
    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;
    				}
    			}
    		}
    		ajax.send(null);
    		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;
    }

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    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
    Code:
    isNull(variable)

  3. #3
    Join Date
    Nov 2007
    Location
    Panama
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •