javascript ajax help
- by ngreenwood6
I have the following code.
    var d3_ad = 1;
    function displayD3Ad(){
        var query_string = '?d3_ad='+d3_ad;
        query_string += '&location='+escape(location);
    //document.write('<iframe src="index.php'+query_string+'"></iframe>');
    var data = httpRequest('http://localhost/test/index.php','GET',query_string);
    document.write(data);
}
function httpRequest(strURL,type,query) {
    var request = false;
    if (window.XMLHttpRequest) {// Mozilla/Safari
        request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { //Internet Explorer
        request= new ActiveXObject("Microsoft.XMLHTTP");
    }
    request.open(type, strURL + query, true);
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    request.onreadystatechange = function() {
        if (request.readyState == 4) {
            return request.responseText;
        }
    }
    request.send(null);
}
displayD3Ad();
now when it writes out the data it is saying undefined. It seems like it isnt returning the data. I looked in firebug and it completes and shows the response that shoudl be there. Any help is appreciated. I just need to set the data variable so that I can use it later on.