Jeff Ferland
Jeff Ferland

Reputation: 18312

AJAX on Internet Explorer: Setting innerHTML to xmlhttp.responseText fails

document.getElementById("livesearch").innerHTML=xmlhttp.responseText; //fails on IE: "Unknown runtime error". Line & character index is for the start of the word document. Works in Firefox.

document.getElementById("livesearch").innerHTML="Something special"; //works

alert(xmlhttp.responseText); // works on IE (done as a debug test)

Target of "livesearch" is a <div id="livesearch></div> block

Upvotes: 0

Views: 2501

Answers (2)

Angolao
Angolao

Reputation: 992

don`t insert HTML code under non-block element.

<p>
<div id="livesearch></div>
</p>

<a href="xxx">
<div id="livesearch></div>
</a>

you should:

<div id="xxxxx">
<div id="livesearch></div>
</div>

Upvotes: 0

Robot Woods
Robot Woods

Reputation: 5687

The content you're trying to insert has to be complete html in the strictest sense. One example I saw was: trying to insert <tr><td>data</td></tr> gives that same runtime error because without <table> actually in the code you're inserting, IE drops the <tr> and <td> tags, and you're trying to insert untagged text.

here was that example (user froufrou had posted this elsewhere): http://www.ericvasilik.com/2006/07/code-karma.html

Upvotes: 2

Related Questions