I got the text database file with jQuery.get() method successfully in my previous post. Like most computer application, the next step is see how to manipulate the source database.
Let’s review the structure of this simple text database (urlData.txt):
This is obvious that each line is a record. Each record has only a data (url). In other words, there are total three records in urlData.txt text database. Of course, each record can have more than one data, with each data separate with delimiter, for example:
The overall concept is to get the database, get the required record, and finally get the required data.
Okay! Let’s see how to handle the passed back text database.
This is quite obvious that the first step after getting the text database is to see how to get each record.
In order to get each record, we have to split the whole trunk of text database into individual record (or line). And then getting each record. This is as shown in the example below:
The results will be shown as below when open the web page:
Here’s the procedures:
- Each record of the text database is linked by the carriage return (“\n”). Therefore we need to split the carriage return that linked the the whole truck of record.
- After splitting the whole trunk of records into individual records or lines. We can get the individual records by specifying the corresponding element number. The first record has element number 0, the second record has element number 1, etc…
The number of lines or records is: lines.length
jQuery example File:
Actually this method of getting individual record is almost the same as other computer programming.