-4

How do I read/check if a file in the same folder of the page exists, when I open the html page locally. The page is made for local use only.

ThePat02
  • 27
  • 1
  • 1
  • 6

1 Answers1

-3

try making an ajax request to retrieve the file. Example with jQuery:

$.get('url to your local file')
.done(()=>{ alert('file exists'); })
.fail(()=>{alert('file cannot be retrieved');});
Eriks Klotins
  • 4,042
  • 1
  • 12
  • 26
  • I get the popup "file cannot be retrieved" – ThePat02 Mar 28 '18 at 12:27
  • if the file actually exists, make sure the url is correct and you run your script and access the file from the same domain. e.g. http://localhost/ – Eriks Klotins Mar 28 '18 at 12:36
  • As said, the file is opened locally, so there is no domain. It is offline. – ThePat02 Mar 28 '18 at 12:37
  • see here: https://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local You may need to install a local server for such functionality – Eriks Klotins Mar 28 '18 at 12:44