使用ie和jQuery“拒绝权限”

时间:2022-11-11 22:25:27

I try to do an AJAX call with jQuery and $.post in 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和$进行AJAX调用。发布在Internet Explorer中,但我得到的只是一个错误,说“权限被拒绝”。这个问题有点奇怪,因为它只在我访问其他页面之后才会出现。

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.)

例如,我在adress行中输入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

test.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。

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

试一试:http://t1318.greatnet.de/ietest/test.html

2 个解决方案

#1


28  

From the post on jquerys forum here, you have to have the content type meta as the first item in your head tag.

从jquerys论坛的帖子来看,您必须将内容类型meta作为头标签中的第一项。

<!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>

#2


0  

If its local (localhost), then for security reasons you have to have the full path.

如果它的本地(localhost),那么出于安全原因,您必须拥有完整的路径。

#1


28  

From the post on jquerys forum here, you have to have the content type meta as the first item in your head tag.

从jquerys论坛的帖子来看,您必须将内容类型meta作为头标签中的第一项。

<!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>

#2


0  

If its local (localhost), then for security reasons you have to have the full path.

如果它的本地(localhost),那么出于安全原因,您必须拥有完整的路径。