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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page called with XmlHttpRequest can't have Javascript?

Status
Not open for further replies.

bryan888

Programmer
Jul 9, 2008
2
US
I'm using XmlHttpRequest to get the content of the file and display it. I have a little bit of javascript on the page being retrieved, but that javascript isn't work. Is there a way to get it read the javascript properly?

Thanks,
bryan
 
Thank you very much for the reply.

I put in this:

document.getElementById('changerDiv').innerHTML = eval(http_request.responseText);

("changerDiv" is the div that the content is to be displayed in), and that resulted in some of the pages not being loaded at all.
 
You can do it like this.
[tt]
//add some non-empty filler ahead of it (somehow arbitrary)
var s="<span style='display:hidden;'>&nbsp;<\/span>";
s+=http_request.responseText;
var oelem=document.getElementById("changerDiv");
oelem.innerHTML="";
if (!!window.ActiveXObject) {
oelem.insertAdjacentHTML("beforeEnd",s);
} else if (!!window.netscape) {
var r=document.createRange();
r.setStartBefore(oelem);
var ohtmlfrag=r.createContextualFragment(s);
oelem.appendChild(ohtmlfrag);
}
[/tt]
You should be done. Note also that for ie, defer attribute is needed for the script component. That you've to do the design proper at server-side.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top