2011-12-09 1 views
4

私のフォームから別のドメインにあるIFRAMEにデータをPOSTしたい。これを行う簡単な方法はありますか?クロスドメインポストiframe

<iframe name="iframe" width="100" height="100" src="www.otherdomain.com" /> 

<form action="www.mydomain.com" method="post" target="iframe"> 
<input type="text" name="text1" value="123" /> 
<input type="text" name="text2" value="456" /> 
<input type="submit" value="submit"/> 
</form> 

答えて

5

あなたの例はうまくいくはずです。私は2つの仮想ホストを設定しましたpastefrom.com pasteto.com 私のlocalhostに。

http://pastefrom.com/index.html

<!DOCTYPE HTML> 
<html> 
<head> 
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
    <title>test</title> 
</head> 
<body> 
<iframe name="iframe" id="iframe" src="http://pasteto.com/index.php" width="500" height="500"></iframe> 

<form action="http://pasteto.com/index.php" method="post" target="iframe"> 
    <input type="text" name="search" value="google" /> 
    <input type="submit" value="submit"/> 
</form> 

</body> 
</html> 

http://pasteto.com/index.php:上

<pre><?php var_dump($_POST);?></pre> 

そして、それはpasteto.com

array(1) { 
    ["search"]=> 
    string(6) "google" 
} 
上のポストデータを示して提出