Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert responseXML to Iframe

Status
Not open for further replies.

nminaker

Technical User
Jun 17, 2004
19
0
0
I have an iframe on my page and I'm querying a database using AJAX to get an XML result.

I want the insert the XML result into the iFrame on the page.

I tried
Code:
document.getElementById('iframeName').innerHTML = ajaxXMLHttp.responseXML

and also a few other variations. The things I found when I googled it... but none seem to work.

Thanks!

Nick
 
Sorry, I suppose that is a little ambiguous, isn't it?

"iframeName" is actually the ID of the iFrame.
 
Have you tried setting the RequestHeader content type to xml???

Code:
xmlHttpObj(whatever you called it).setRequestHeader("Content-Type", "text/xml");

I'm pretty sure .responseXML won't return anything w/o this set.



[monkey][snake] <.
 
I'm sure this all works because I did have the results from the responseXML placed into a drop down. I just wanted to add more information than the select/options could easily and nicely display.
 
Duh, I was being stupid, I ran across this


Since iframe is a frame, it must be reponded to as a frame.

So start with the frame reference, THEN the document object.

Start by giving your frame a name, we'll say frame1.

So we do
Code:
window.frames["frame1"].document.body.innerHTML = ajaxXMLHttp.responseXML

like the link shows. It does make sense though.



[monkey][snake] <.
 
monksnake, you shouldn't need the frames[] reference, but you're right about the following .document.body.innerHTML...

in other words - you should still be able to use:

Code:
document.getElementById("iframeName").document.body.innerHTML = ajaxXMLHttp.responseXML;



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
You are referencing the iframe within document. I'm not saying you're wrong, you're most likely right. I just need to test this. That's why I chose the frames array reference, I know that works, wasn't sure about your way.

BRB

Code:
[!]document[/!].getElementById("iframeName").

[monkey][snake] <.
 
Hmm I just tested this, and that way doesn't actually work.

Code:
document.getElementById("iframeName").document.body.innerHTML = ajaxXMLHttp.responseXML;

It added the innerHTML to the main page body, not the iframe body.

Thanks though, now I definitely know what's what.



[monkey][snake] <.
 
Thanks guys. Looks like the real problem was that I needed the iFrame to have a name, not just the ID.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top