我正在尝试在jsp的qTip2工具提示中显示从servlet响应接收到的文本(或html).我几乎所有的东西都在工作,并且已经用Firebug验证了正在调用servlet并且返回了文本,但是当我尝试在ajax调用中使用’html'(或数据)变量时,出现错误:HierarchyRequestError:Node不能在层次结构中的指定点插入.
我尝试在JavaScript警报中显示html,这是显示的内容:[object XMLDocument].
这是事件的顺序:
1.用户单击HTML文本的一部分,该部分具有定义的链接,该链接指向Servlet并传递参数
2. ajax调用servlet进行一些处理并返回文本或html
3.使用qTip2将文本显示为工具提示
如何正确处理servlet的响应并处理从servlet接收的文本?
Ajax呼叫:
$(".ajax_link").click(function(e) {
e.preventDefault();
var $this = $(this);
var link = $(this).attr('href'); //Gets link url
$.ajax({
type: "GET",
url: link,
cache: false,
}).done(function(html) {
$this.qtip({
content: {
text: html //<--this causes error above
//text: "<table><tr><th>Team</th></tr></table>" <--this works fine
}
});
$this.qtip('toggle', true);
});
});
Servlet代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("inside doGet");
String var1 = "<table><tr><th>Team</th></tr></table>";
//var1 = request.getParameter("var1");
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.print(var1);
out.flush();
out.close();
}
解决方法:
在ajax请求中将dataType作为html传递
即
$.ajax({
type: "GET",
url: link,
cache: false,
dataType : "html"
}
原文地址:https://codeday.me/bug/20191120/2044299.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。