Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My HTML snippetes content not show in the display

Can someone explain to me about the HTML snippets? See the image below (w3schools HTML snippets tutorial). Then I create a "content.html" file according to w3schools instructions. Then I create another .html file and then use the same code but don’t show any content to the display. Can someone explain me how to use it?

enter image description here

When I try to my computer –

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

enter image description here

>Solution :

There is actually an error that occurred when loading your page that should that you can find in your console log similar to

html.html:1

Access to XMLHttpRequest at ‘file:///content.html’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, edge, https, chrome-untrusted.

This occurs as a result of the file being loaded using the file protocol rather than the HTTP protocol, due to the absence of a web server. As browsers do not allow you to load local files using the File protocol using an HTTP request. Which is what the code below is trying to do.

xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4) {
        if (this.status == 200) {elmnt.innerHTML = this.responseText;}
        if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
        /*remove the attribute, and call this function once more:*/
        elmnt.removeAttribute("w3-include-html");
        includeHTML();
    }
} 

To get this to work on your local system you would have to set up a web server. And access the HTML file using localhost. Depending on your intentions for implementing this you could look for a web server that will be suitable. However, I would advise Apache Server, using XAMPP which is relatively easy to install.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading