Home > Web Front-end > JS Tutorial > body text

jQuery $.get 的妙用 访问本地文本文件_jquery

WBOY
Release: 2016-05-16 17:51:58
Original
1251 people have browsed it

场景: 当页面文件.html作为本地文件打开(即IE路径为file:///开头的)的时候,需要访问本地文本文件的内容时。
本地文件目录在页面文件的子文件夹。
目录结构

|-test.html
|-Scripts
|-data.txt

需要访问data.txt的内容。
代码:

复制代码 代码如下:

$.get('Scripts/data.txt').success(function(content){
// content就为文件data.txt的文本内容了,注意txt文件的编码需要与html文件的编码一致,最好保存成utf-8
});
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!