PDA

View Full Version : problem in innerHTML and xmlReq.responseText


migueldesousa
03-03-2008, 06:53 PM
hi there,
in IE i have the follow problem:
when i try to do this
document.getElementById("minhaDiv").innerHTML=xmlReq.responseText;
it gives me an "Unknown error",
if i do
document.getElementById("minhaDiv").innerHTML="x";
or
var x = "X";
document.getElementById("minhaDiv").innerHTML=x;
its ok
any ideias ????
thank you in advance

mjlorbet
03-03-2008, 08:15 PM
your response text may be containing <!doctype>, that will give you an error, or, it could be containing <html>...</html> those also will give you errors, try this


var xrt = xmlReq.responseText;
xrt = xrt.substr(xrt.indexOf("<body"));
xrt = xrt.substr(xrt.indexOf(">") + 1);
xrt = xrt.substr(0, xrt.indexOf("</body>"));
document.getElementById("minhaDiv").innerHTML = xrt;

* may need some tweaking

but this will only return the code inside the body tag on the page requested which would be the safe area to use. Also, reassigning the innerHTML property after its contents become "not literal" will raise an error like that, it is possible that you would have to empty the collection of objects within the div or span or whatever you're using with something like this


var lastChildCount = document.getElementById("minhaDiv").children.length;
while(document.getElementById("minhaDiv").children.length > 0)
try{ document.getElementById("minhaDiv").removeChild(document.getElementById("minhaDiv").children[0]); document.getElementById("minhaDiv").children.length = lastChildCount-1;}catch(ee){}
if(lastChildCount == document.getElementById("minhaDiv").children.length)
break;


give those a whack, should give you something more meaningful if not fixing the problem