Home >Web Front-end >JS Tutorial >A small example of Jquery accessing XML data through Ajax_jquery

A small example of Jquery accessing XML data through Ajax_jquery

WBOY
WBOYOriginal
2016-05-16 17:14:24990browse

Page js code

Copy code The code is as follows:

$.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
Copy code The code is as follows:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn