如何阅读使用javascript文件的内容是什么? [英] How to read contents of a file using javascript?

查看:104
本文介绍了如何阅读使用javascript文件的内容是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入类型=文件按钮。当我选择一个文件,我要读使用JavaScript文件的内容。是否有可能读取/获得使用JavaScript和AJAX选定的文件的内容?

I have an input type="file" button. After I choose a file, I have to read the contents of the file using javascript. Is it possible to read/get contents of a chosen file using javascript or ajax?

推荐答案

使用AJAX其可以读取上传的文件,但与纯JavaScript它不是可能的,因为JavaScript的工作在客户端而不是断绝身边。

With AJAX its possible to read uploaded file but with pure javascript its not possible because javascript works on client side not on sever side.

如果你要使用jQuery比Ajax调用可能是这样

if you are going to use jquery than Ajax call may be like this

$.ajax({
  url: "test.html",
  context: document.body,
  success: function(){
    $(this).addClass("done");
  }
});

这篇关于如何阅读使用javascript文件的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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