ReadFile not working offline

req=ReadFile(“myfile.txt”) used to work (Offlineapp.manifest) before going to PWAs with the ServiceWorker. With extraFiles containing the name of the text file upon a full deploy to the server this file can be seen in the Application/Cache Storage when running Chrome on a PC. It’s there along with all of the other picture files used by the app and those work properly when offline. Is there some other method to use for reading these cached files?

I also tried req=Ajax("myfile.txt’), no luck.

Thanks, John

Its my understanding ReadFile is for reading a file on the server where the webapp is deployed.

Your ajax call for reading a file will need to call a php file to read a file on your server.

In my code I have
`

> req=Ajax("ajaxGetURL.php/?urlToGet="&filename)

`

The php file on the server looks like this

> <?php
> error_reporting(-1);
> $a = file_get_contents($_GET['urlToGet']);
> echo $a;
> ?>

I’m trying to read a file when the Internet is offline, so reading a php script on the server cannot be accessed.

As stated, reading a file with ReadFile while offline worked in previous Offlineapp.manifest apps, now with PWA it does not work. Providing the full link to the server was also tried, but failed.

Thanks, John

Are there any error messages on the Console?

Error in Consol: jquery2.js:4 GET https://prograsa.com/hw/version.txt net::ERR_INTERNET_DISCONNECTED

where hw is the name of the app deployed to the server.

Testing with AS sample HelloWorld with Button1 modified and property Make PWA? = True:

 Function Button1_onclick()
  'MsgBox "Thanks for clicking!"
  C = "version.txt"
  req=ReadFile(C)
  'req=Ajax(C,"POST")
  If req.status = 200 Or req.status = 0 Then
    C = req.responseText
    alert("got version.txt: " & req.status & ":" & C)
  Else
    alert("unable to get file")
  End If
End Function

where version.txt is in extraFiles.

Deploy to server, run the app and the correct number in version.txt is returned with Button1_onclick.

From Chrome go to consol (F12) and select Application/Cache Storage and all of the cached files are there, including version.txt.

Select Network/offline. Press Button1_onclick and req.status is 0, not 200, and req.responsText is undefined.

Thanks, John