如何解析JQUERY 通过AJAX请求来的HTML数据

2024-12-14 11:03:28
推荐回答(1个)
回答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("

");
out.println("

test dom tree

");
out.println("
");
out.flush();
out.close();
}