Home Misc Index
Include (HTML) file via XMLHttpRequest
 P van Diemen

This page demonstrates how an HTML-page may load another file without 'server-side include' actions.  It uses an XMLHttpRequest in JavaScript.  The loaded file can be of any type (e.g. text, XML, HTML), and is returned as a string.
Note however, that if an HTML-file is to be included in the current page, that file should not be a normal HTML-page, but only an HTML-fragment (the Body contents).  But a JavaScript may strip that of the returned string.

If you add a timed routine, you can automatically refresh the include, or load a different include everytime the interval expires.

URI/URL:  absolute addresses (full path) are obviously correct, but relative references (e.g. ./Fragment.html) also work.  And protocol ('http:') is also not required.
Cross-domain access (referencing to another web-domain) is not allowed;  that will result in 'Access denied' !
Observed characteristics:  The included file is not easily refreshed (i.e. it comes from cache) !  So automatically refreshing an include might not work.
 
URL:
 
The following is the file indicated above (after pressing Load) presented as text
Click on the Load-button above

Automatically included file (./Fragment.html):