“权限被拒绝” .加载 IE 上的当前页面
假设我正在服务器的子文件夹上测试一个站点,例如 http://12.123.12.12/domain.tld/
。当我在根页面上时,我可以愉快地执行
$('#dummy').load('http://12.123.12.12/domain.tld/page.html')
(将触发警告成功消息的回调函数。)但是,如果我尝试,
$('#dummy').load('http://12.123.12.12/domain.tld/folder/page.html')
我仅在 IE 中收到“权限被拒绝”错误(同源策略错误)。
如果省略 IP 地址,即 $('#dummy').load('/domain.tld/...')
,我会得到相同的成功/失败。我不知道为什么 IE 会这样;它只是一个子文件夹。 (事实上,它是带有 .html
扩展插件的 WordPress,但我看不出这是问题所在。)
编辑: 事实证明我只得到了拒绝的权限加载我当前正在浏览的页面时。例如,假设我的浏览器指向http://12.123.12.12/domain.tld/folder/page.html,如果我随后尝试
$('#dummy').load('http://12.123.12.12/domain.tld/folder/page.html')
,则会发生错误。
Say I'm testing a site on the sub-folder of a server, e.g. http://12.123.12.12/domain.tld/
. When I'm on the root page, I can happily do a
$('#dummy').load('http://12.123.12.12/domain.tld/page.html')
(A callback function alerting a success message would fire.) However, if I try
$('#dummy').load('http://12.123.12.12/domain.tld/folder/page.html')
I get the 'permission denied' error only in IE (same origin policy error).
I get the same success/failure if I omit the IP address, i.e. $('#dummy').load('/domain.tld/...')
. I have no idea why IE would behave like this; it's just a subfolder. (In fact, it's Wordpress with a .html
extension plugin, but I can't see that being the issue.)
edit: It turns out I get the permission denied only when loading the page that I'm currently browsing. For instance, assume my browser is pointed at http://12.123.12.12/domain.tld/folder/page.html
, if I then try
$('#dummy').load('http://12.123.12.12/domain.tld/folder/page.html')
then the error occurs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
拒绝权限来自同源政策。从文件夹访问数据不会成为问题。我猜测您的浏览器地址中的内容不是
http://12.123.12.12/domain.tld
。Permission denied is from the same origin policy. Accessing data from a folder is not going to be the issue. I am guessing that what is in the address for your browser is not
http://12.123.12.12/domain.tld
.因此,正如所描述的,确切的问题是 IE 不喜欢加载已经存在的 URL。如果浏览器位于中任何
page.html
的http://123.12.12.12/domain.tld/page.html
任何子目录结构,以下 jQuery 都会失败:失败的特点是“权限被拒绝”错误,通常与同源策略相关。
要解决此问题,请在请求中附加一个虚拟对象,这会强制 jQuery 将其作为 POST 请求(而不是默认的 GET)发送,例如:
并且负载现在按预期工作。
So, as described, the precise problem is that IE didn't like loading a URL if it was already on it. If the browser is at
http://123.12.12.12/domain.tld/page.html
for anypage.html
in any sub-directory structure, the following jQuery would fail:The failure is characterised by a 'Permission denied' error, commonly associated with the same origin policy.
To fix the problem, append a dummy object to the request, which forces jQuery to send it as a POST request (rather than the default GET), e.g.:
and the load now works as expected.