[英]uncaught error NOT_FOUND_ERR DOM Exception 8
So I am deleting all the contents under a particular div and adding a message content. 所以我删除特定div下的所有内容并添加消息内容。 However, javascript throw the following error after the finish: 但是,javascript在完成后抛出以下错误:
Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
Here is the code where it is executed 这是执行它的代码
new Ajax.Request("profileThis.php",
{
method:'post',
parameters:{title:title, review:review, userId:userId, category:category, categoryId:categoryId},
onSuccess:function(ajax)
{
alert(ajax.responseText); // this is just for debugging purposes
var message=ajax.responseText;
var divMessage=document.createElement("div");
divMessage.style.color="rgb:(105,105,105)";
divMessage.innerHTML=message;
while($("reviewSheet").hasChildNodes)
{
$("reviewSheet").removeChild($("reviewSheet").lastChild);
}
$("reviewSheet").adopt(divMessage);
},
onFailure:ajaxFailure,
onException:ajaxFailure
});
People commented that the problem was with how I assigned divMessage
to reviewSheet
. 人们评论说问题在于我如何将divMessage
分配给reviewSheet
。 I tried both adopt
and appendChild
but none works. 我试过adopt
和appendChild
但没有一个工作。 A little help would be appreciated. 一点帮助将不胜感激。
divMessage.style.color="rgb:(105,105,105)";
应该
divMessage.style.color="rgb(105,105,105)";
Is the problem that you are calling the method hasChildNodes() on a jQuery object? 您是否在jQuery对象上调用方法hasChildNodes()的问题? I'm not sure what $("reviewSheet") is supposed to be, but wrapping a string in $() makes it a jQuery object which I don't believe will work with regular javascript methods. 我不确定$(“reviewSheet”)应该是什么,但是在$()中包装一个字符串会使它成为一个jQuery对象,我认为它不适用于常规的javascript方法。 If "reviewSheet" is the id of an element you could do something like 如果“reviewSheet”是元素的id,你可以做类似的事情
node = document.getElementById('reviewSheet');
then you could go into your while loop. 然后你可以进入你的while循环。
while (node.hasChildNodes()) {
//the rest of your code here
}
Oh also you need to put the parenthesis after hasChildNodes() to return a boolean value. 哦,你还需要在hasChildNodes()后面加上括号来返回一个布尔值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.