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

The wonderful use of jQuery $.get to access local text files_jquery

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

Scenario: When the page file .html is opened as a local file (that is, the IE path starts with file:///), the content of the local text file needs to be accessed.
The local file directory is in the subfolder of the page file.
Directory structure

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

Need to access the content of data.txt.
Code:

Copy code The code is as follows:

$.get('Scripts/ data.txt').success(function(content){
// content is the text content of the file data.txt. Note that the encoding of the txt file needs to be consistent with the encoding of the html file. It is best to save it as 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!