私はこの質問が古いことを知っていますが、ここで私はASP.Net(C#)でjQueryを使って行っています。
//Create the form in a jQuery object
$("<form action='/FormPostTo.aspx' method='post' target='nameofframe'></form>")
//Get the value from the asp textbox with the ID txtBox1 and POST it as b1
.append($("<input type='hidden' name='b1' />").attr('value',$('#<%= txtBox1.ClientID %>').val()))
//Get the value from the asp textbox with the ID txtBox2 and POST it as b2
.append($("<input type='hidden' name='b2' />").attr('value',$('#<%= txtBox2.ClientID %>').val()))
//Add the form to the body tag
.appendTo('body')
//Submit the form which posts the variables into the iframe
.submit()
//Remove the form from the DOM (so subsequent requests won't keep expanding the DOM)
.remove();
だけで簡単なメモ:私はテキストボックスの値の中に引用符('
)を持っていたという場合には、それらを連結するよりも、そのような入力タグをしました。連結した場合、HTMLが壊れて正しく解析されません。
また、使用した後にフォームをDOMから削除するので、iFrameに複数回投稿するとフォームの要素でDOMを埋めることはありません。
あなたが作ることができるわずかな変更は、存在しない場合はフォーム要素を作成し、既に存在する場合はIDで参照して再利用することです。ここ
。私が望むのは、ユーザーが送信ボタンをクリックすることなく、外部からiframeに投稿を送信することだけです。 srcを使用してiframeに渡すことはできません。なぜなら、必要なクエリーストリングパラメータではないからです。