views:

9973

answers:

4

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.

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?

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.

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

A: 

Basically, this error occurs when the document in frame and outside of ii have different domains. So to prevent cross-side scripting browsers disable such execution.

dimarzionist
I am posting to the same domain.
Ovesh
A: 

if it is a domain issue (or subdomain) such as www.foo.com sending a request to www.api.foo.com

on each page you can set the

document.domain = www.foo.com

to allow for "cross-domain" permissions

Causas
+5  A: 

Solved it by myself!

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

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.

Ovesh
I'm uploading file using fileupload.js (it uses iframe). Looks like i have same issue, but i'm not sure what may cause this. Looks like just timeout issue. How did you prevent that?
Lion_cl
I'm not sure I understand the question. In any case, if you think it's related to my solution, you should have a look at the HTTP code returned with the response the upload.
Ovesh
A: 

I know this question is super-old, but I wanted to mention that the above answer worked for me: setting the document.domain to be the same on each of the pages-- the parent page and the iframe page. However in my search, I did find this interesting article:

http://softwareas.com/cross-domain-communication-with-iframes

Groovetrain