donboe
November 26, 2018, 10:48am
1
For a small test i’m working on I use the following function to load several sections in index.html (html5):
$(function(){
$("#include-header").load("header.html");
$("#include-footer").load("footer.html");
});
But noting gets loaded. Both header.html and footer.html exists, and are in the same location as index.html and I have jQuery included as well. What can be the reason they are not loaded?
Hey donboe,
Do elements with the specified ids exist on the page?
What does the network tab of your browser tools say? Is the request being fired off?
Are there any errors in the terminal?
donboe
November 26, 2018, 11:25am
3
Hi Pullo. Everything well I hope?
Yes the elements exist with the right id’s
Mmmmm This is what I get in the terminal
jquery-3.1.1.min.js:6 Access to XMLHttpRequest at ‘file:///E:/DesignDevelopment/Sections/public_html/header.html’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
So I know the reason now!
Just install a HTTP server and all should work as desired.
This is the one I use: https://www.npmjs.com/package/http-server
Start it in the same directory as the file you want to serve, then navigate to http://127.0.0.1:8080/
1 Like
donboe
November 26, 2018, 12:14pm
5
system
Closed
February 25, 2019, 7:15pm
6
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.