×

Jquery通过Ajax访问XML数据的小例子

作者:Terry2017.02.09来源:Web前端之家浏览:10014评论:0
关键词:JQueryJS

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

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1486569600845.html

网友评论文明上网理性发言已有0人参与

发表评论: