如何解析JQUERY 通过AJAX请求来的HTML数据
1个回答
展开全部
Javascript代码:
$.ajax({
url:'/htmltest',
type:'get',
dataType:'xml',
timeout:1000,
error:function() {
alert("request error!");
},
success:function(da
ta) {
alert(da
ta);
$(da
ta).find("div").each(function() {
var text = $(this).text();
alert(text);
});
}
});
Java代码:
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
httpServletResponse.setContentType("text/xml;charset=utf-8");
httpServletResponse.setHeader("Cache-Control","no-cache");
PrintWriter out = httpServletResponse.getWriter();
out.println("<div>");
out.println("<p>test dom tree</p>");
out.println("</div>");
out.flush();
out.close();
}
$.ajax({
url:'/htmltest',
type:'get',
dataType:'xml',
timeout:1000,
error:function() {
alert("request error!");
},
success:function(da
ta) {
alert(da
ta);
$(da
ta).find("div").each(function() {
var text = $(this).text();
alert(text);
});
}
});
Java代码:
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
httpServletResponse.setContentType("text/xml;charset=utf-8");
httpServletResponse.setHeader("Cache-Control","no-cache");
PrintWriter out = httpServletResponse.getWriter();
out.println("<div>");
out.println("<p>test dom tree</p>");
out.println("</div>");
out.flush();
out.close();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询