How to handle json response response to cross-domain iframe file?

I am creating a file upload API.

Basically, the user will need POST files with his / her api_key + signature on my web service. Then my web service responds to a JSON response. I am wondering how this process can work asynchronously?

Assuming the user submits the request in the form, setting the target in the iframe. A JSON response will be sent to the user on his / her iframe with the content type set to "text / html". It is set as "text / html" instead of "application / json" because I want to avoid using the "pre" tag introduced by the browser around the JSON response. In any case, how does the user read the JSON response if there is a different domain in the iframe and parent window? There will be a problem with cross power.

Dynamically creating a "script" tag plus JSONP will not work in this case, because I need POST to load. JSONP only works with GET requests.

+4
source share
2 answers

Due to the same origin policy, browsers do not allow JavaScript in the main frame, viewing / accessing any content in the iframe from another domain. In this case, users will have to use easyXDM or create their own proxy server through a proxy here, I mean that users will have to write code on their server, which can communicate with your API so that the mail request is sent directly to your server, and get will get a response from its own proxy.

0
source

Take a look at the Download example here . It uses cross-messaging to send messages to the download page and uses easyXDM to support all browsers.

This post explains how it all works!

+1
source

Source: https://habr.com/ru/post/909605/


All Articles