许可使用Javascript / jQuery的本地文件被拒绝 [英] Permission Denied using Javascript/jQuery on a local file

查看:109
本文介绍了许可使用Javascript / jQuery的本地文件被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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>

我继承这个块的HTML和JavaScript以上(片段)。据/将要被用作本地帮助。目前,它是唯一的网上和正常工作。然而,当我在本地复制文件时,我收到权限被拒绝在Internet Explorer和Chrome浏览器没有做任何事情,当我点击这里获取更多的帮助。什么它应该做的是从装载直列help.html的帮助内容和helpdiv DIV显示。现在这里是踢球,如果我采取相同的文件,将它们复制到INETPUB我的电脑上,并加载它们为的http://本地主机/hello.html 该功能完好。

presumably这是一个安全的事情,其中​​的本地区域不允许我加载文件从用户的高清?但我真的不知道发生了什么,想明白这个问题进一步,并可能拿出一个解决办法。

Presumably this is a security thing where the "local" zone isn't allowing me to load files off of the user's HD? But I'm not really sure what's going on and would like to understand this problem further and potentially come up with a workaround.

任何了解大大AP preciated。

Any insight is greatly appreciated.

推荐答案

jQuery的获取使用xmlHtt prequest,这不会对本地文件的工作,很遗憾。如果你真正需要的是能够(从不同的域或数据)读取本地数据不同步,您应该使用动态脚本标记。然而,这意味着该数据文件已被重新格式化为JSON数据。

jquery's "get" uses xmlHttpRequest, which doesn't work on local files, unfortunately. If you really need to be able to fetch local data (or data from a different domain) asynchronously, you should use dynamic script tags. However that means the data file has to be reformatted as JSON data.

这篇关于许可使用Javascript / jQuery的本地文件被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆