0

I have a simple html with included another html via jquery:

<!-- included.html -->
<ul>
   <li><a href="home.html">Home</a></li>
   <li><a href="about.html">Page 2</a></li>
   <li><a href="contact.html">Page 3</a></li>
</ul>

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script>
    $(document).ready(function() {
    $('#myinc').load('included.html');
    });
    </script>
</head>
<body>
<div id="myinc"></div>
</body>
</html>

Firefox+IE shows me the list but Chrome not (empty page). Any solutions?

Many thanks

lucullus
  • 9
  • 2

2 Answers2

1

It is about chrome security features. If you run it from your local that is not work but if you work on server it will be work

1

In the Chrome Console (Click F+12) you can see the error like this:

XMLHttpRequest cannot load file:///C:/...temp/included.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Chrome has web security.

The solitions may be:

  1. Disable web security in Chrome

Disable same origin policy in Chrome

  1. Or put you file into http server, and write a path to file

    $('#myinc').load('http://mysitedotcom/included.html');

  2. Or run index.html using the local server.

Community
  • 1
  • 1
Olga
  • 266
  • 2
  • 7