Mon code:NOT_FOUND_ERR: DOM Exception 8 - javascript
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>
J'obtiens l'erreur: NOT_FOUND_ERR: DOM Exception 8 pour la ligne commentBox.insertBefore(response, commentBox.firstChild);
Mais commentBox est bien défini beca utiliser quand je vérifie avec l'alerte (commentBox) il me montre l'objet.
Quelle est l'erreur?
Avez-vous essayez d'utiliser 'textContent' au lieu de' Text'? – Musa
non, ce n'est pas que je l'ai essayé. merci quand même. –
@Vlenorroia Qu'est-ce que 'response'? Est-ce un noeud DOM? Si c'est une chaîne, alors vous utilisez abusivement ['insertBefore'] (https://developer.mozilla.org/en-US/docs/DOM/Node.insertBefore), et votre question est un doublon de [javascript appendChild doesn 't work] (http://stackoverflow.com/questions/7041740/javascript-appendchild-doesnt-work) et [Erreur non détectée: NOT_FOUND_ERR: DOM Exception 8 pour l'appel appendChild] (http://stackoverflow.com/questions/ 11640367/uncaught-erreur-non-trouvé-erreur-dom-exception-8-pour-appendchild-call) – apsillers