gpt4 book ai didi

javascript - NOT_FOUND_ERR : DOM Exception 8 - javascript

转载 作者:行者123 更新时间:2023-11-28 02:26:35 25 4
gpt4 key购买 nike

我的代码:

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 the line commentBox.insertBefore(response, commentBox.firstChild);

但是 commentBox 定义良好,因为当我检查alert(commentBox) 时,它会向我显示该对象。

错误是什么?

最佳答案

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

var response=xmlhttp.responseXML.getElementsByTagName("theComment")[0].textContent;
commentBox.insertBefore(document.createTextNode(response), commentBox.firstChild);

关于javascript - NOT_FOUND_ERR : DOM Exception 8 - javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14842168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com