html5中文学习网

您的位置: 首页 > 网站及特效实例 > javascript特效 » 正文

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

[ ] 已经帮助:人解决问题

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

(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助