62,074
社区成员
发帖
与我相关
我的任务
分享
JQ读取XML文件,貌似有问题,我看不出来,大伙帮忙看看!
<?xml version="1.0" encoding="utf-8"?>
<menu>
<url type="111">
<loc>stitch山西是个坏淫</loc>
</url>
<url>
<loc>stitch山西是个大坏淫</loc>
</url>
<url>
<loc>小鸟是个好淫</loc>
</url>
</menu>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SelectXmlByJq.aspx.cs" Inherits="SelectXmlByJq" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(function () {
$("#Read").click(function () {
$.ajax({
type: "GET",
url: "XMLFile1.xml",
dataType: "xml",
error: function (xml) {
alert("加载xml出错");
},
success: function (xml) {
$(xml).find("url").each(function (i) {
var location = $(this).attr("type").text();
var text = $(this).children("loc").text();
$("<a>").attr("href", location)
.text(text)
.css({ "width": "600px", "float": "left" })
.appendTo("#Wirte");
});
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<a id="Read" href="#" style="width: 700px;">点击读取XML</a>
</div>
<div id="Wirte">
</div>
</form>
</body>
</html>
$.ajax({
url:"xml/1.xml",
dataType:"xml",
success: function(xml) {
$(xml).find("url").each(function (i,v) {
var location = $(v).attr("type")==undefined?"":$(v).attr("type");
var text = $(v).children("loc").text();
$("<a>").attr("href", location).text(text).css({ "width": "600px", "float": "left" }).appendTo("#Wirte");
});
}
})