Today, I am going to discuss how to use jQuery to read a text file or text database. Sometimes we only need a text database when the data is not so sensitive or unimportant. Let’s see how jQuery read text file.
jQuery.get() or $.get() Method
The jQuery.get() method simply send a request to the text file or other files and get the result back. In this case the text file must be stored in the same hosting account and the URL must be specified. Let’s take an example to see how to use jQuery.get() to read a text file.
In the above example:
- the text file is a small database containing the urls of some websites.
- the text file is stored in the same hosting of the web page.
- the url of the text file must be specified.
The result will be as shown below:
Look! The contents of the text file has been passed back successfully.
jQuery example File:
We got the contents of the text database. It now depends on how we like to use it.