Reputation: 7839
I have a AJAX form and I use this line on receiving a response:
document.getElementById("output").innerHTML = xmlhttp.responseText;
Output is a div and in IE I'm getting an Unknown JavaScript Error.
Would it be the content that's being passed from the AJAX that's causing this error or is there something syntactically wrong with that line?
EDIT:
if(valid==true){
//AJAX
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("output").innerHTML = xmlhttp.responseText;
id = document.getElementById("parentID").value;
}
}
var parameters = "shedloadofvariables"+shedloadofVariables;
xmlhttp.open("POST", "register.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(parameters);
}
else{
alert("Please Fill in All Fields");
}
Cheers
Upvotes: 1
Views: 1277
Reputation: 7839
I still don't understand the problem fully (Andy E's answer certainly helps though).
I found a work-around for this issue:
var t = document.createElement('div');
t.innerHTML = xmlhttp.responseText;
document.getElementById("output").appendChild(t);
Flawless.
Don't know why, but I'm not about to question it, because it works!
Upvotes: 1
Reputation: 344537
Output is a div and in IE I'm getting an Unknown JavaScript Error.
"Unknown runtime error" commonly occurs when setting invalid HTML via the innerHTML
property. Not all invalid HTML will cause this problem — the common case is trying to stuff a block element into an element that doesn't allow block elements, like a <div>
inside a <p>
. Only IE spits out this error message, other browsers will do their best to recover from your crappy HTML.
First thing to do is validate the HTML with the W3C validator. For more information, take a look at http://blog.rakeshpai.me/2007/02/ies-unknown-runtime-error-when-using.html.
Upvotes: 3