当前位置:编程学习 > XML/UML >>

Jquery通过Ajax访问XML数据

页面js代码

$.ajax({

url : '...',
type : 'POST',
dataType : 'xml',
error : function(xml) {
alert("Error loading XML document" + xml);
},
success : function(xml) {
$(xml).find("X").each(function(i) {
alert($(this).attr("Xattr"));
});
}
});

后台输出代码

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

response.setContentType("text/xml; charset=utf-8");
response.setCharacterEncoding("utf-8");

PrintWriter pw = response.getWriter();
Document doc = new Document();//获取XML文件
doc.write(pw);
return null;
}



摘自 asd309202533的专栏
补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,