Permission Denied Javascript / jQuery in local file

function publish(text) { $('#helpdiv').prepend(text); } function get_help(topic) { $.get(topic, publish); } <p>Hi. <a href="#" onclick="get_help('inline-help.html'); return false;">click here for more help.</a></p> <div id="helpdiv"></div> 

I inherited this piece of HTML and javascript above (snippet). This / will be used as local assistance. Currently, it only works on the Internet, and it works fine. However, when I copy files locally, I get "Permission Denied" in Internet Explorer and in Chrome does nothing when I "click here for more help." What he should do is load the help contents from inline-help.html and display it in a div div. Now here is the kicker, if I take the same files and copy them to inetpub on my PC and download them as http: //localhost/hello.html , it works fine.

Presumably, this is a security thing where the "local" zone does not allow me to download files from user HD? But I'm not quite sure what is happening, and I would like to further understand this problem and, perhaps, come up with a workaround.

Any insight is greatly appreciated.

+3
source share
2 answers

jquery "get" uses xmlHttpRequest, which, unfortunately, does not work with local files. If you really need to receive local data (or data from another domain) asynchronously, you should use dynamic script tags. However, this means that the data file must be reformatted as JSON data.

+1
source

I don't think your browser allows you to run javascript locally (using the file:/// access method. But when you download it from http://localhost/ , it works fine.

You need to either develop on the website or use your localhost server.

0
source

Source: https://habr.com/ru/post/1310576/


All Articles