javascript ajax help

Posted by ngreenwood6 on Stack Overflow See other posts from Stack Overflow or by ngreenwood6
Published on 2010-04-30T19:44:20Z Indexed on 2010/04/30 19:47 UTC
Read the original article Hit count: 273

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about AJAX