【发布时间】:2015-12-24 16:30:06
【问题描述】:
刚开始学习jQuery,所以对错误等深层机制不太了解。
我正在使用 jQuery 解析 html 页面的 xml 文件,我的文件夹结构按以下方式构建
客户
-CurrentFiles
-test.xml
-stations
-test.html
我正在使用 Google 的 jQuery cdn 来加载 jQuery 库。
这是我的代码
<script type="text/javascript">
var data = [];
$(document).ready(function () {
$.ajax({
type:'post', //just for ECHO
dataType: "xml", // type of file you are trying to read
url: './../CurrentFiles/test.xml', // name of file you want to parse
success: parse, // name of the function to call upon success
async: false,
error: function(xhr, status, error) {
alert("error");
console.log(error);
console.log(status);
}
});
function parse(xmldata) {
$(xmldata).find("value").each(function(){
alert($(this).text());
data.push($(this).text());
});
}
console.log("data array:" + data);
});
</script>
xml文件格式如下
<?xml version="1.0" encoding="utf-8"?>
<values>
<value date="2015-07-12">37.170</value>
<value date="2015-07-13">7.190</value>
<value date="2015-07-12">37.170</value>
<value date="2015-07-12">3.210</value>
<value date="2015-07-12">37.20</value>
我得到的错误是
DOMException [NS_ERROR_DOM_BAD_URI:“访问受限 URI 被拒绝”
代码:1012
nsresult:0x805303f4
地点:https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js:4]
我真的不明白这个错误是在我这边,文件不能有写权限还是在处理 CDN?
顺便说一句,我使用的是Firefox。
【问题讨论】: