“访问被拒绝"访问 iframe 文档对象时出错 [英] "Access is denied" error on accessing iframe document object

查看:27
本文介绍了“访问被拒绝"访问 iframe 文档对象时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在具有许多参数的表单中发布 AJAX 表单,我使用的解决方案是创建一个 iframe,通过 POST 将表单发布到它,然后访问 iframe 的内容.具体来说,我正在访问这样的内容:

For posting AJAX forms in a form with many parameters, I am using a solution of creating an iframe, posting the form to it by POST, and then accessing the iframe's content. specifically, I am accessing the content like this:

$("some_iframe_id").get(0).contentWindow.document

我测试了它并且它起作用了.

I tested it and it worked.

在某些页面上,我开始收到访问被拒绝"错误.据我所知,如果 iframe 是从同一域提供的,则不会发生这种情况.

On some of the pages, I started getting an "Access is denied" error. As far as I know, this shouldn't happen if the iframe is served from the same domain.

我很确定它以前是有效的.有人有线索吗?

I'm pretty sure it was working before. Anybody have a clue?

如果我说得不够清楚:我将发布到同一个域.所以这不是跨域请求.我只在 IE 上测试.

If I'm not being clear enough: I'm posting to the same domain. So this is not a cross-domain request. I am testing on IE only.

附言我不能使用简单的 ajax POST 查询(不要问...)

P.S. I can't use simple ajax POST queries (don't ask...)

推荐答案

自己解决了!

问题是,即使发送了正确的响应(使用 Fiddler 验证),发送的响应也是 HTTP 500 错误代码(而不是 200).

The problem was, that even though the correct response was being sent (verified with Fiddler), it was being sent with an HTTP 500 error code (instead of 200).

事实证明,如果发送的响应带有错误代码,IE 会将 iframe 的内容替换为从磁盘加载的错误消息(res://ieframe.dll/http_500.htm),导致跨域访问被拒绝错误.

So it turns out, that if a response is sent with an error code, IE replaces the content of the iframe with an error message loaded from the disk (res://ieframe.dll/http_500.htm), and that causes the cross-domain access denied error.

这篇关于“访问被拒绝"访问 iframe 文档对象时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆