jQuery 无法在层次结构中的指定点插入节点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8159640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:08:47  来源:igfitidea点击:

Node cannot be inserted at the specified point in the hierarchy

jqueryajax

提问by Ber53rker

So I'm trying to load plain text from an outside file into my page and I keep getting the error in the title. What am I doing wrong? (I followed the tutorial exactly!) Thanks.

所以我试图将外部文件中的纯文本加载到我的页面中,但我一直在标题中收到错误消息。我究竟做错了什么?(我完全按照教程!)谢谢。

HTML

HTML

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="ajax.js"></script>
</head>

<body>
<input id="button" type="button" value="Load" />

<div id="content"></div>
</body>
</html>

JQuery

查询

$("#button").click(function(){
    $.ajax({
      url:"AjaxRequest.html",
      success:function(data) {
      $("#content").html(data);
      }
    });
 });

EDIT: It is apparently no successful. Not sure why, the file is there right next to it.

编辑:显然没有成功。不知道为什么,文件就在它旁边。

回答by Jeff Lauder

Try specifying a dataType:

尝试指定一个数据类型:

$("#button").click(function(){
   $.ajax({
      url:"AjaxRequest.html",
      dataType:'html',
      success:function(data) {
        $("#content").html(data);
      }
   });
});

回答by Gjohn

try

尝试

$("#content").append('<p>'+data+'</p>');