如何将本地磁盘上的文本文件读入javascript中的变量
问题描述:
您好我正在尝试从本地计算机读取.json文件。它不会在我使用的代码中读取它:
Hi I am trying to read in a .json file from my local machine. it will not read it in the code I am using is:
jQuery.getJSON('../json/test.json')
.done(function(data) {
var test = data;
alert("sucsess");
})
.fail(function(data){
alert("failed");
});
所有我从中得到的都是失败的我做错了什么。我没有通过这个服务器。
All I am getting from this is failed what am I doing wrong. I am not going through a server with this.
答
使用文件API。以下是示例代码和演示的指南:
Use the File APIs. Here's a guide with sample code and demos:
- Reading files in JavaScript using the File APIs