PDA

View Full Version : AJAX - Accessing id values inside responseText after statechange



ratherblue
April 12th, 2007, 01:14 PM
A little AJAX fun, been messing with this for the past two days:


request = new XMLHttpRequest();

request onreadystatechange = function(){
if(request.readyState == 4){
var ajaxDisplay = document.getElementById('displayDiv');
ajaxDisplay.innerHTML = request.responseText;
}
}

Now here's the problem. After I have set displayDiv to whatever the responseText was, I can't access the id's inside it using document.getElementById. I get the nice "...has no display properties" error because the document physically does not contain the responseText.

I know other people have run into this problem, and I am wondering what you did to fix it :)

ratherblue
April 12th, 2007, 02:01 PM
Update:

From further reading it seems the root of the problem is that I am using "responseText" and not "responseXML". (Problem still unsolved)

ratherblue
April 12th, 2007, 02:21 PM
Update:

The content-type of your response MUST be set to "text/html" in order to use responseXML. Now I get "[object XMLDocument]" as my response :)