How to insert text from an external file into a div?

As the name says; I want the contents of an external file (text, html, php, etc.) on a div. There is text text in the external file: text_1.txt or * text_1.html *, and I want this text to appear in the div that is on the main page.


An ideal solution would be a fairly simple code to display text from a text or html file by inserting it into the div: content class

Here I illustrated the problem with the underlying code, use this as an example to write a solution.

Code in text_1.html:

<p>Hello world.</p> 

Code in index.html:

 <!doctype html> <html> <head> <title>Homepage</title> </head> <body> <div class="content"></div> </body> </html> 

It is as simple as I can put it. I appreciate all the answers I get, thanks.

PS here are some things you should avoid answering:

  • Use iframes or any other frame type solution.
  • Use onclick function in jQuery etc.
  • Use ineffective text fields to replace specific text.
  • Use embed code for a virtual server or similar methods.
+4
source share
2 answers

Why don't you just do it with jquery

 $(document).ready(function() { $('.content').load('text_1.html'); }); 
0
source

It is impossible to do this if and until you use the server side. Includes use of PHP, ASP or JSP

http://en.wikipedia.org/wiki/Server_Side_Includes

If you want to do this with php you can use this:

 require_once('filename.php'); /* For including files */ 

Or use your own functions to open .txt files on your pages

+2
source

All Articles