【发布时间】:2016-01-09 07:46:51
【问题描述】:
我目前正在从本地 xml 文件中获取数据。但是我的代码不起作用。我尝试了很多解决方案,但没有一个不适合我。 “data.xml”文件与“index.html”在同一个文件夹中。我正在使用 Chrome 进行测试。
数据.xml
<?xml version="1.0" encoding="utf-8"?>
<Names>
<Name id="10" />
<Name id="11" />
</Names>
index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Resources/jquery-1.8.3.min.js"></script>
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "data.xml",
dataType: "xml",
success: function (xml) {
$(xml).find('Name').each(function (element) {
var sTitle = $(element).attr('id');
alert(sTitle);
});
}
});
});
</script>
</head>
【问题讨论】: