Jquery is a small example of accessing XML data through Ajax

  • 2020-03-29 23:48:20
  • OfStack

Page js code


$.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"));
});
}
});

Background output code

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();//Get the XML file
doc.write(pw);
return null;
}


Related articles: