爱程序网

ajax访问xml文件代码实例

来源: 阅读:

ajax访问xml文件代码实例:
xml文件现在还算是使用非常频繁,下面是一段使用jquery ajax访问xml文件的实例代码,非常的简单,希望能够给需要的朋友带来一定的帮助,代码实例如下:
一.ajax代码:

 

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

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=10640

更多内容可以参阅:http://www.softwhy.com/jquery/

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助