我正在尝试使用JQuery来读取和解析文本文件,并且我正在使用的代码似乎出错了。使用javascript读取文件
//Attempt 6
alert("Test Alert 9"); //js file does load into index.html
$.get("exchanges.txt",
function(data) {
//idk what the following two lines do, I got them from:
//http://api.jquery.com/jquery.get/
$(".result").html(data);
alert("check it");
})
//should execute if works?
.done(function() {
alert("second success");
})
//should execute if any error
.fail(function() {
alert("error");
})
.always(function() {
alert("finished");
});
以下提示打印:
- “检测警报9”
- “错误”
- “已完成”
我的问题: 是有办法检查什么的错误是? 和/或没有人知道错误可能是什么?
编辑:为了澄清,exchanges.txt文件位于同一文件夹中的js文件
编辑:更新抛出错误控制台。错误打印:
XMLHttpRequest cannot load file:///C:/Users/Invictus/Documents/GitHub/BTCExchangesMaterialize/exchanges.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
通过将exchanges.txt移动到主文件夹而不是js /文件夹来修复此错误。
新的错误:
XMLHttpRequest cannot load
file:///C:/Users/Invictus/Documents/GitHub/BTCExchangesMaterialize/exchanges.txt.
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.jquery-2.1.1.min.js:4 n.ajaxTransport.k.cors.a.crossDomain.sendjquery-2.1.1.min.js:4 n.extend.ajaxjquery-2.1.1.min.js:4 n.each.n.(anonymous function)exchangesParser.js:3 (anonymous function)
检查浏览器的网络选项卡(开发人员工具)看看什么是休息..也失败处理程序有一个状态参数 – 2015-02-24 03:57:02
其中是** exchanges.txt **? – 2015-02-24 03:59:35
exchanges.txt文件位于与js文件 – 2015-02-24 04:00:39