Joshua
Joshua

Reputation: 136

unable to load the data to html file from a text file called sample.txt using jQuery

I have a text file called sample.txt and I want to load the data of that file using following HTML file but it would not be loading.

$( document ).ready(function() {
  jQuery.get('sample.txt', function(theData) {
    alert(theData);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Alert data from text file</h1>
<div><p id="fileData"></p></div>

Upvotes: 2

Views: 50

Answers (1)

Tobias Sch&#228;fer
Tobias Sch&#228;fer

Reputation: 1358

If you are running locally this can cause errors: Error while running locally.

See this question for more details

Running the HTML code using XAMPP and calling localhost it works without error. JQuery.get... is not working using file:/// protocol.

Upvotes: 2

Related Questions