0

When trying to get the responseText from an ajax call built in plain vanilla javascript, Firebug seems to see the request but one cannot get a reference to the responseText.

This is the code for function

function getAjaxResponse(){    
    var ajaxObj = getAjaxObj();
    ajaxObj.open('get', 'responsePage.php', true);
    ajaxObj.onReadyStateChanged = function(){
        if(ajaxObj.readyState == 4
            && ajaxObj.status == 200){
                //no functions are getting fired in here                
                //this does not get logged to console
                console.log(ajaxObj.responseText);
                //neither does this
                console.log(2);
        }
    };
    ajaxObj.send(null);

   //this does gets logged to console
   console.log(1);
}

function for the ajax object

function getAjaxObj(){
    var req;  
    if(window.XMLHttpRequest){
        try{
            req = new XMLHttpRequest();                                                                 
        } catch(e){
            req = false;
        } finally {
            return req;
        }
    } else {
        if(window.ActiveXObject){
            try{
                req = new ActiveXObject("Msxml2.XMLHTTP");
            } catch(e){
                try{
                    req = new ActiveXObject("Msxml.XMLHTTP");
                } catch(e){
                    req = false;
                } finally {
                    return req;
            }
            }
        }
    }
}

Also here is the view from firebug enter image description here

How to get a reference to the response from the ajax call?

1

2 Answers 2

2

OnReadyStateChanged needs to be onreadystatechange. JavaScript is case-sensitive.

Sign up to request clarification or add additional context in comments.

1 Comment

Haha.. thanks so much was getting well p!#$#d. Will accept your answer as soon as it will let me! cheers
1

ajaxObj.onReadyStateChanged: onreadystatechange should all be lower case (and without the trailing 'd')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.