开发者

"Permission denied" with Internet Explorer and jQuery

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.

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

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 work开发者_如何学Pythons, 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?

edit: A small example:

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

It works!

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


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

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜