Home >Web Front-end >JS Tutorial >The wonderful use of jQuery $.get to access local text files_jquery

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

WBOY
WBOYOriginal
2016-05-16 17:51:581333browse

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
});
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