Javascript Internet Explorer 和 jQuery 的“权限被拒绝”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2960153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Permission denied" with Internet Explorer and jQuery
提问by rallex
I try to do an AJAX call with jQuery and $.postin Internet Explorer, but all I get is an error saying "Permission denied". The problem is kinda weird since it occurs only when I access a page after I was on any other page.
我尝试使用 jQuery 和$.postInternet Explorer进行 AJAX 调用,但我得到的只是一个错误,提示“权限被拒绝”。这个问题有点奇怪,因为它只在我访问任何其他页面之后访问页面时发生。
For instance I type the URL in the adress line and let IE load the page. Then I click on a button so the script should start loading JSON data. (The script providing the data lies on the same server and I access it with a relative URL, so using a different domain is not the problem here. Even tried to use a absolute URL with the same host part.)
例如,我在地址行中输入 URL 并让 IE 加载页面。然后我单击一个按钮,以便脚本开始加载 JSON 数据。(提供数据的脚本位于同一台服务器上,我使用相对 URL 访问它,因此使用不同的域在这里不是问题。甚至尝试使用具有相同主机部分的绝对 URL。)
But when I refresh the page then and try it again it works! Same thing when I come to that page from another page. At first nothing works, but when I click "refresh" everything is fine.
但是当我刷新页面并再次尝试时,它可以工作!当我从另一个页面来到那个页面时,同样的事情。起初没有任何效果,但是当我单击“刷新”时一切正常。
IE gives me the error message "Permission denied" while in every other browser I don't notice this behaviour. Since I have tried many things and still cannot imagine where the problem lies I'd like to ask you what you think the problem might be?
IE 给了我错误消息“权限被拒绝”,而在其他所有浏览器中我都没有注意到这种行为。由于我尝试了很多方法仍然无法想象问题出在哪里,我想请问您您认为问题是什么?
edit:A small example:
编辑:一个小例子:
test.html
测试.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<script type="text/javascript" src="/ietest/jquery.js"></script>
<script type="text/javascript" src="/ietest/test.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<a href="#">Test</a>
</body>
</html>
ajax.html
ajax.html
It works!
test.js
测试.js
$(document).ready(function(){
$( 'a' ).click(function(){
$.post( '/ietest/ajax.html', function( data ) {
alert( data );
});
});
});
Try it here: http://t1318.greatnet.de/ietest/test.html
回答by Gordon Tucker
From the post on jquerys forum here, you have to have the content type meta as the first item in your head tag.
从此处的jquerys 论坛上的帖子中,您必须将内容类型元作为 head 标记中的第一项。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/ietest/jquery.js"></script>
<script type="text/javascript" src="/ietest/test.js"></script>
</head>
<body>
<a href="#">Test</a>
</body>
</html>
回答by adardesign
If its local (localhost), then for security reasons you have to have the full path.
如果是本地(本地主机),那么出于安全原因,您必须拥有完整路径。
回答by Wilson
In my case, changing the jquery version worked. Instead of using version 1.9.1, now I'm using 1.12.4 and it works.
就我而言,更改 jquery 版本有效。而不是使用版本 1.9.1,现在我使用 1.12.4 并且它可以工作。

