AJAX responseText

The response text that I have coming back is a complete HTML page.
Is there any way to set that response text to a document... and get the innerHTML of an element by ID???

So right now I have on my callback javascript

document.getElementById("ajax-div").innerHTML = http_request.responseText;

I would like it to be something like...

document.getElementById("ajax-div").innerHTML = http_request.responseText.getElementById("html-for-ajax").innerHTML;
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

responseText is a string object, and unfortunately I do not believe it is possible to do as you propose.
responseXML returs an xml stream object, which has methods similar to what you want, but the response has to be in XML format.  I've never tried using it on something that is in HTML format.  You may want to try it just to see what will happen.

Your alternative would be to change the return of the ajax request to only return the html you want, or to parse the entire html to retrieve the data you want.
Something like this:
text = responseText.value.match(/<div id=\"yourelementid\">(.*?)<\/div>/);
document.getElementById("ajax-div").innerHTML = text[0];
document.getElementById("ajax-div").innerHTML = text[0];
This should be:
document.getElementById("ajax-div").innerHTML = text[1];
cophiAuthor Commented:
>>responseText.value.match(/<div id=\"yourelementid\">(.*?)<\/div>/);

Would that work if I have other div's inside this div??

>>Your alternative would be to change the return of the ajax request to only return the html you want, or to parse the entire html to retrieve the data you want.

I tried this method in my ASP.Net Application, but I don't know of a good way to parse it.  Do you?
responseText.value.match(/<div id=\"yourelementid\">(.*?)<\/div>/);
This will match every thing between the div tags, including other divs:

<div id=yourlementid>This is my innerHTML<div>So is this</div></div>
The above would return
"This is my innerHTML<div>So is this"

If you want to retrieve simple text, have the asp page return simple text only.  That way, no parsing is involved.  If I want to retrive the number of miles form here to there, my page should simply return the miles and nothing else.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.