2

I know this kind of questions have been asked a numerous times. But i am confused as no answer really helped me.

Problem:

I have a .txt file on http://example.come/test.txt.

And I want to do is display all the contents of the txt file using JS in a test.html file.

Any help is appreciated...

Krishna Raj Salim
  • 7,331
  • 5
  • 34
  • 66
psharma
  • 1,279
  • 2
  • 19
  • 47
  • 2
    If you're using jQuery, have you tried any of these: http://api.jquery.com/category/ajax/shorthand-methods/, http://api.jquery.com/load/ specifically? – slamborne Feb 28 '13 at 09:46
  • http://www.scriptsplash.com/2009/07/simple-ajax-request-loading-text-file.html – Dipesh Parmar Feb 28 '13 at 09:48

1 Answers1

2

You can make an Ajax call to receive the contents of the text file and than insert it into you DOM. It should be something like this:

<html>
<head>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script>
        $(function() {
            $.get('text.txt', function(data) {
                $('#text-file-container').html(data);
            });
        });
    </script>
</head>
<body>
    <div id="text-file-container"></div>
</body>
</html>
Vadim
  • 8,701
  • 4
  • 43
  • 50