頁面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;
}