We help IT Professionals succeed at work.

Include text.txt file content in main.html page

New_Alex
New_Alex asked
on
I have 2 files.

c:\main.html
c:\text.txt

How can I include the text from the text file text.txt in my Main.html page ?

Thank you,,,,

Comment
Watch Question

Kiran SonawaneProject Lead
Top Expert 2011

Commented:

<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<script>
  $(document).ready(function(){
    $.get('text.txt', function(data) {
            var lines = data.split("\n");
            $.each(lines, function(n, elem) {
                $('#myContainer').append('<div>' + elem + '</div>');
            });
        });
   
  });
  
</script>
<body>
  <div id="myContainer"></div>
</html>

Open in new window

Author

Commented:
Thank you sir