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

Commented:
you can use activex object or xmlhttprequest (AJAX). You need to use javascript in both conditions.
check this link: http://social.msdn.microsoft.com/Forums/en-US/sidebargadfetdevelopment/thread/64ea2d16-7594-400b-8b25-8b3b9a078eab
Kiran SonawaneProject Lead
Top Expert 2011

Commented:
You can do like this
Here is code for main.html


<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

You can it it by including the following, formatting as you need

<td>
<object width="625" height="300" type="text/plain" data="http://www.myufd.com/message.txt" border="0" >
</object>
</td>

Author

Commented:
Thank you sir