未捕获的错误 NOT_FOUND_ERR DOM 异常 8

发布于 2024-12-06 23:54:38 字数 998 浏览 5 评论 0原文

所以我删除特定 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。我尝试了 adoptappendChild 但都不起作用。 如果有一点帮助,我们将不胜感激。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁与争疯 2024-12-13 23:54:38
divMessage.style.color="rgb:(105,105,105)";

应该是

divMessage.style.color="rgb(105,105,105)";
divMessage.style.color="rgb:(105,105,105)";

should be

divMessage.style.color="rgb(105,105,105)";
耶耶耶 2024-12-13 23:54:38

问题是您在 jQuery 对象上调用 hasChildNodes() 方法吗?我不确定 $("reviewSheet") 应该是什么,但是将字符串包装在 $() 中使其成为一个 jQuery 对象,我不相信它可以与常规 javascript 方法一起使用。如果“reviewSheet”是一个元素的 id,您可以执行类似的操作

node = document.getElementById('reviewSheet');

,然后您可以进入 while 循环。

while (node.hasChildNodes()) {
 //the rest of your code here
}

哦,您还需要在 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

node = document.getElementById('reviewSheet');

then you could go into your while loop.

while (node.hasChildNodes()) {
 //the rest of your code here
}

Oh also you need to put the parenthesis after hasChildNodes() to return a boolean value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文