未捕获的错误 NOT_FOUND_ERR DOM 异常 8
所以我删除特定 div 下的所有内容并添加消息内容。然而,javascript 在完成后抛出以下错误:
Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
这是执行它的代码
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
});
人们评论说问题在于我如何将 divMessage
分配给 reviewSheet
。我尝试了 adopt
和 appendChild
但都不起作用。 如果有一点帮助,我们将不胜感激。
So I am deleting all the contents under a particular div and adding a message content. However, javascript throw the following error after the finish:
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
. I tried both adopt
and appendChild
but none works.
A little help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该是
should be
问题是您在 jQuery 对象上调用 hasChildNodes() 方法吗?我不确定 $("reviewSheet") 应该是什么,但是将字符串包装在 $() 中使其成为一个 jQuery 对象,我不相信它可以与常规 javascript 方法一起使用。如果“reviewSheet”是一个元素的 id,您可以执行类似的操作
,然后您可以进入 while 循环。
哦,您还需要在 hasChildNodes() 之后添加括号以返回布尔值。
Is the problem that you are calling the method hasChildNodes() on a jQuery object? 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. If "reviewSheet" is the id of an element you could do something like
then you could go into your while loop.
Oh also you need to put the parenthesis after hasChildNodes() to return a boolean value.