【发布时间】:2013-01-28 07:51:05
【问题描述】:
我的代码:
function SubmitCommentAJAX(i)
{
var thecomment = i.parentNode.getElementsByClassName("styled")[0].innerHTML;
var commentBox = document.body.getElementsByClassName("commentsScroll")[0];
var request = "http://localhost:8080/ituned.com/index?Event=Comment&PostTitle=<%=p.getTitle()%>&PostOwner=<%=p.getUsername_of_Owner()%>&comment="+thecomment;
xmlhttp.open("POST",request,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var response=xmlhttp.responseXML.getElementsByTagName("theComment")[0].text;
**commentBox.insertBefore(response, commentBox.firstChild);**
}
};
}
HTML:
<div class="commentsScroll" align="left">
<div></div>
</div>
</div>
我收到错误:NOT_FOUND_ERR: DOM Exception 8 for line commentBox.insertBefore(response, commentBox.firstChild);
但是commentBox 的定义很明确,因为当我检查alert(commentBox) 时,它会向我显示对象。
错在哪里?
【问题讨论】:
-
你试过用
textContent代替text吗? -
不,不是我试过。无论如何,谢谢。
-
@Vlenorroia
response是什么?它是一个 DOM 节点吗?如果它是一个字符串,那么你在滥用insertBefore,你的问题是javascript appendChild doesn't work和Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 for appendChild call的重复
标签: javascript exception dom insertion