0

I'm trying to read text from a file saved in my website's directory but keep getting a 404 error when attempting to find it.

The directory structure is simple in this example:

+ - index.html
|
+ - README.md
|
+ - license.txt
|
+ - js
     |
     + - app.js

Inside of app.js I have the following function that allows one to look for files and read their text.

    function findPostContent(file) {
        var rawFile = new XMLHttpRequest();
        var allText = {};
        rawFile.open("GET", file, false);

        rawFile.send();

        if (rawFile.status === 200 || rawFile.status === 0) {
            allText = rawFile.responseText;
            return;
        }

        console.log("can't find file");

        return allText;
    }

When I run it looking for license.txt it finds it without fail. However when I run it looking for README.md I get a 404.

findPostContent("license.txt"); // Works fine!
findPostContent("README.md");   // 404?

Anyone have any insights as to why this is occurring? I thought this might be a security issue, per this question but if so, why is it able to read license.txt without fail?

Community
  • 1
  • 1
prestonsmith
  • 758
  • 1
  • 9
  • 29

0 Answers0