未找到错误:DOM异常8-javascript

未找到错误:DOM异常8-javascript,javascript,exception,dom,insertion,Javascript,Exception,Dom,Insertion,我的代码: function SubmitCommentAJAX(i) { var thecomment = i.parentNode.getElementsByClassName("styled")[0].innerHTML; var commentBox = document.body.getElementsByClassName("commentsScroll")[0]; var request = "http://localhost:8080/ituned.co

我的代码:

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);**
        }
    };
}
<div class="commentsScroll" align="left"> 
    <div></div>             
    </div> 
</div>
函数submitcommontajax(i)
{
var thecomment=i.parentNode.getElementsByClassName(“styled”)[0].innerHTML;
var commentBox=document.body.getElementsByClassName(“commentsScroll”)[0];
var请求=”http://localhost:8080/ituned.com/index?Event=Comment&PostTitle=&PostOwner=&comment=“+委员会;
open(“POST”,请求,true);
xmlhttp.send();
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{            
var response=xmlhttp.responseXML.getElementsByTagName(“theComment”)[0]。文本;
**insertBefore(response,commentBox.firstChild)**
}
};
}
HTML:

<div class="commentsScroll" align="left"> 
    <div></div>             
    </div> 
</div>

我得到错误:未找到\u错误:行
commentBox.insertBefore(response,commentBox.firstChild)的DOM异常8

<div class="commentsScroll" align="left"> 
    <div></div>             
    </div> 
</div>
但是commentBox定义得很好,因为当我选中alert(commentBox)时,它会显示对象

<div class="commentsScroll" align="left"> 
    <div></div>             
    </div> 
</div>
错误是什么?

采用dom节点,因此必须将文本转换为文本节点

<div class="commentsScroll" align="left"> 
    <div></div>             
    </div> 
</div>
var response=xmlhttp.responseXML.getElementsByTagName("theComment")[0].textContent;
commentBox.insertBefore(document.createTextNode(response), commentBox.firstChild);
获取dom节点,因此必须将文本转换为文本节点

<div class="commentsScroll" align="left"> 
    <div></div>             
    </div> 
</div>
var response=xmlhttp.responseXML.getElementsByTagName("theComment")[0].textContent;
commentBox.insertBefore(document.createTextNode(response), commentBox.firstChild);

你试过用
textContent
代替
text
吗?不,不是我试过的。反正是thanx。@Vlenoroa什么是
响应
?它是DOM节点吗?如果它是一个字符串,那么您是误用了,您的问题是重复的,您是否尝试使用
textContent
而不是
text
?不,不是我尝试了它。反正是thanx。@Vlenoroa什么是
响应
?它是DOM节点吗?如果它是一个字符串,那么你是误用了,你的问题是重复的,你真的是对的!!但在您没有放置createtextnode之前,这就是它不起作用的原因。塔克斯!不仅字符串,而且包含DOM节点的单元素数组都是
insertBefore
的无效参数。为什么我认为
splice
并不总是返回数组?:-)你真的是对的!!但在您没有放置createtextnode之前,这就是它不起作用的原因。塔克斯!不仅字符串,而且包含DOM节点的单元素数组都是
insertBefore
的无效参数。为什么我认为
splice
并不总是返回数组?:-)