Javascript: returning result from parent function within XMLHttpRequest callback

Discussion in 'JavaScript' started by naldz, Aug 28, 2006.

  1. #1
    Hi, this is my first time to post here and i hope someone could help me with my problem.

    I have a function that wraps an XMLHttpRequest call and im planning to return the result of the request call as the result of the container function...

    example:

    function getValueFromServer(){
    if(window.XMLHttpRequest) var req = new XMLHttpRequest();
    else if(window.ActiveXObject) req = new
    ActiveXObject("Microsoft.XMLHTTP");

    httpRequest.open("GET",reqUrl,false);
    httpRequest.onreadystatechange = handleRequest;
    httpRequest.send(null);

    function handleRequest(){
    if(req.readyState == 4){
    return req.responseText; // I want this return call to be the return call of the container function getValueFromServer
    }
    }
    }


    any ideas?
     
    naldz, Aug 28, 2006 IP