简体   繁体   中英

How to read last value of a txt file in javascript

I have a server side script which outputs result in a txt file. And the value stored in the txt file is like

1
2
5
7
10

As I want to make a realtime progress bar I have to take last value each time with ajax request while updating the txt file with serverside results. So how can I grab the last value of the file with the help of javascript?

Or, is there any way to save the current value to the file with removing previos value as there will be only one value in the file? I am using php as server side script.

Or, is there any way to save the current value to the file with removing previos value as there will be only one value in the file?

Obviously, yes.

$result = file_put_contents($path, strval($progress));
if($result === false) {
  // Error while writing to disk
}

This will replace the file contents, overwriting all previous values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM