Cenzy Digeno
Cenzy Digeno

Reputation: 61

Error when replacing div with external html using jQuery

I have a external page 'divone.htm' and I want replace the content of mainbox with content of external page's div #divet.

$(document).ready(function(){
    $('#mainbox').load('divone.html #divet');
});

However, the content from the file does not load, and I receive the following error in the console:

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

Upvotes: 0

Views: 134

Answers (1)

Julien Grégoire
Julien Grégoire

Reputation: 17134

In local, Chrome restricts call to local files as if it was from another domain. If divone.html is on same domain as your main page, it will work once on server.

Firefox doesn't have the same restrictions for local content, you can test locally with it.

You can also launch Chrome from command line/terminal and add --allow-file-access-from-files as an argument to remove this restriction. Exact way to call vary depending on your OS.

Upvotes: 2

Related Questions