0

I have a set of data organized into .txt files. I want to display the content of the .txt files on an HTML page using jQuery.

My jQuery:

$(document).ready(function(){

    //works:
    $("#test").html("what");

    //doesn't work:
    $.get("test.txt", function(data) {
        $("#test").html(data);
        alert("loaded: "+data);
    });

    //doesn't work:
    $("#test").load("test.txt", function(){
        alert("loaded");
    });
});

Both methods I have seen (.get and .load) fail to work for me. The HTML does not change from "what" and no alerts display. I have looked around for around an hour, but all I can find are solutions claiming that these methods work, even though they do not for me. What am I doing wrong?

(And yes, test.txt is in the same folder. The html, js, and txt are all in one folder together.)

tshepang
  • 12,111
  • 21
  • 91
  • 136
mboisseau
  • 23
  • 3
  • Check the browser's network tab. – Ram May 20 '14 at 02:33
  • I checked the network tab and it says that "Origin null is not allowed by Access-Control-Allow-Origin." EDIT: **For those having this issue, it's because Chrome doesn't allow you to load local files. Try using a different browser while you test or just use a test server.** – mboisseau May 20 '14 at 02:43
  • This is a related question http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-access-allow-for-file – Ram May 20 '14 at 02:47

0 Answers0