场景: 当页面文件.html作为本地文件打开(即IE路径为file:///开头的)的时候,需要访问本地文本文件的内容时。
本地文件目录在页面文件的子文件夹。
目录结构
|-test.html
|-Scripts
|-data.txt
需要访问data.txt的内容。
代码:
$.get('Scripts/data.txt').success(function(content){
// content就为文件data.txt的文本内容了,注意txt文件的编码需要与html文件的编码一致,最好保存成utf-8
});
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn