1

I'm building a website, and I need to access a file called friends.txt and get the first element.

I then use it in the folder name to display some pictures. The problem is that jquery.get seems to have security restrictions and I can only get it to work in Internet Explorer. Should I do something else to read a server side file?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
    $.get("friends.txt", function(data){
        var text = data.split("/");
        var p1 = text[0];
            var x = document.createElement("IMG");
            x.setAttribute("src", "../../Documents/dumpster_shit/FB/"+p1+"/0.jpg");
            x.setAttribute("class","democlass")
            document.body.appendChild(x);
        }
    });
</script>
Ivan
  • 10,052
  • 12
  • 47
  • 78

1 Answers1

0

With a minor correction (I removed an extraneous brace) you code works fine as it is on Chrome.

Proof: http://sam.nipl.net/test-friends.html , http://sam.nipl.net/friends.txt

Are you trying to test it locally on your own computer, using a file:/// URL? Some browsers have security features to prevent you accessing local files using ajax. For Chrome, you need to use this command line option:

chrome --allow-file-access-from-files

You could also try running your test site in a local web server.

Sam Watkins
  • 7,819
  • 3
  • 38
  • 38