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
Release: 2016-05-16 17:14:24
Original
969 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template