Jacek
Jacek

Reputation: 12053

Access-Control-Allow-Origin in Chrome doesn't work, but in FF works

I have some code (below) in my html file, I have second file from which I want to load content. Both files are in the same location

<div id="mainMenu"></div>
<script>
    $(function() {
        $('#mainMenu').load('menu.html');
    });
</script>

Everything works great in FireFox, but I have some problem in Chrome: content doesn't appear. Under developer tools in Chrome I see this information about 'Access-Control-Allow-Origin'. There is screen

I don't use sever code, just HTML and jQuery

enter image description here

What should I do to resolve this problem? Any idea?

Upvotes: 0

Views: 407

Answers (3)

A. Wolff
A. Wolff

Reputation: 74420

You should set a local server to serve page because google chrome doesn't allow access by default to local files. However, you could still change chrome setting using option:

--allow-file-access-from-files

See here for more explanation: http://www.chrome-allow-file-access-from-file.com/

Upvotes: 1

Prasanth K C
Prasanth K C

Reputation: 7332

Preview your website in a local web-server environent (localhost)

As your console the file path is from your local drive,

Setup a localhost using any webserver module and test your website using http://

For Eg:

Use

http://localhost/yourwebsite/

instead of

D:/yourwebsite/

You can use wamp or xamp to setup a local environment.

Upvotes: 0

Philippe Boissonneault
Philippe Boissonneault

Reputation: 3949

You're trying to execute a file and request on localhost.

Try to run this file on localhost (with wamp or local server), not only executing the html. There should not be any cross-origin problem.

Upvotes: 0

Related Questions