开发者

'permission denied' .load'ing the current page on IE

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.


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.


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 any page.html in any sub-directory structure, the following jQuery would fail:

$('#container').load('http://123.12.12.12/domain.tld/page.html');

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

$('#container').load('http://123.12.12.12/domain.tld/page.html', {one : 1});

and the load now works as expected.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜