AJAX inside IFRAME does not work with the same server

I use the abc.com website which hosts the iframe page on 123.com .
The page inside the iframe makes an AJAX request to another page at 123.com , but we see that the request is canceled.

If I am mistaken - and I have not found any official information on the Internet about this - the call should work fine, as this is not a cross-domain request.

Will the fact that the parent frame is in a different domain really prevent the iframe executing AJAX requests to its own server?

+4
source share
1 answer

An IFRAME should be able to make an ajax request to its own source site (same source URL). However, make sure the REQUEST event is RECEIVED from the IFRAME, not the parent.

My first assumption was that you load the IFRAME and then access it (fire the event) through the parent (JS) to force it to do / receive / set something that causes the ajax call. In short, this is most likely the reason that the IFRAME domain for the same domain request is canceled because the browser is still recognized by the browser based on the code of the target domain.

The REQUEST event must be organically generated by the user by clicking on something in the IFRAME or from the code in the IFRAME itself that triggers the event.

In other words: just because an IFRAME may have some ability to fire / ajax events in its JS / code on its own, it is usually not allowed to have a parent link, ajax / JS directly through JS / code. An IFRAME must already be encoded to do this based on its load parameters (possibly URL values), or the user must physically click / take any action to create a user-generated event in this domain.

Of course, this will slightly change the browser and version to what you can talk about in terms of interactivity between the parent and iframe. But a strict, modern browser will try to deter you from falsifying insecure interactions on the iFrame via js.

To get a better answer, you will need to provide more detailed information about what you are doing / getting.

+2
source

All Articles