Reputation: 136
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
Reputation: 1358
If you are running locally this can cause errors:
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