Reputation: 339
I have the following problem.
My Table contains rows which show simple information about an article. If you click on a label, a new <tr>
gets inserted.
In that <tr>
information is displayed. But the problem is, it gets displayed like you view a html document in an Editor.
Like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-32" /> <title>Untitled Document</title> <link href="css/test2.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="search.js"> .......
Not as "translated" html, like it usually does.
The Code i use:
function doDetail(articlenr)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiceXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var partr = document.getElementById("tr"+articlenr);
var newtr = document.createElement("TR");
var newtd = document.createElement("TD");
var content = document.createTextNode(xmlhttp.responseText);
newtr.setAttribute('id', "det"+articlenr);
newtd.colSpan = 8;
newtd.appendChild(content);
newtr.appendChild(newtd);
partr.parentNode.insertBefore(newtr,partr.nextSibling);
}
}
xmlhttp.open("GET","showdetail.php?nr="+articlenr,true);
xmlhttp.send();
}
How can this be solved?
Upvotes: 1
Views: 5191
Reputation: 4927
Replace newtd.appendChild(content);
width newtd.innerHTML = xmlhttp.responseText;
Upvotes: 0
Reputation: 1075587
ajax responseText displayed as text, not html
Yes, you're explicitly doing that with this line:
var content = document.createTextNode(xmlhttp.responseText);
...and then appending that line to newtd
.
If you want the text parsed as HTML, you can assign it to the innerHTML
property of an element. E.g.:
newtd.innerHTML = xmlhttp.responseText;
Upvotes: 3