ajax读取xml文件
xmlAjax.jsp页面:
<%@ page language="java" pageEncoding="utf-8" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>HelloAjax</title> <script src="./js/jquery-1.6.1.js" type="text/javascript"></script> <script type="text/javascript"> function helloAjax() { $.ajax({ type: "post", url: "xx.xml", dateType: "xml", success: function(xml) { $(xml).find("province").each(function() { var t = $(this).attr("name"); $("p").append("<font color=red>省:" + t + "</font><br/>"); $(this).find("city").each(function() { $("p").append("市:" + $(this).text() + "<br/>"); }); }); } }); }; </script> </head> <body> <center> <button onclick="helloAjax()">Ajax</button> <p></p> </center> </body> </html>
xx.xml代码:
<?xml version="1.0" encoding="utf-8" ?> <provinces> <province name="湖北"> <city>武汉</city> <city>黄石</city> <city>宜昌</city> <city>天门</city> </province> <province name="湖南"> <city>邵阳</city> <city>长沙</city> <city>岳阳</city> </province> <province name="广东"> <city>广州</city> <city>深圳</city> </province> </provinces>
执行效果:
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05