如何将本地磁盘上的文本文件读入javascript中的变量 [英] How do I read a text file on my local disk into a variable in javascript

查看:121
本文介绍了如何将本地磁盘上的文本文件读入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

这篇关于如何将本地磁盘上的文本文件读入javascript中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆