load a page using POST to iframe

2019-07-17 23:32发布

问题:

I want to create an iframe with other page visible inside. The page is outside my domain. Normally I do it like that:

$('<iframe />').attr('src','www.thepage.com?data=1').appendTo('body')

But if www.thepage.com is accessible via POST instead of GET, how should I load it? $.ajax( type:'POST',...) fails due to Origin null is not allowed by Access-Control-Allow-Origin.

回答1:

Load in a temporary page that contains a form with the fields you need (hidden) and use Javascript to submit the form.

This happens to be a previous question that I asked. Response.Redirect with POST instead of Get?

Look at the answer from Pavlo. You can see how he's creating an html page with a form that does a submit on load of the body.