Мой код:
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 для строки commentBox.insertBefore(response, commentBox.firstChild);
Но commentBox хорошо определен, потому что когда я проверяю с помощью alert(commentBox), он показывает мне объект.
В чем ошибка?
textContent
вместоtext
? - person Musa   schedule 13.02.2013response
? Это узел DOM? Если это строка, то вы неправильно используетеinsertBefore
, и ваш вопрос является дубликатом javascript appendChild не работает и Uncaught Error: NOT_FOUND_ERR: исключение DOM 8 для вызова appendChild - person apsillers   schedule 13.02.2013