多表單提交的一種解決方案

來源:互聯網
上載者:User

問題:
一個頁面中有兩個表單,點擊一個按鈕時要同時擷取兩個表單的資訊,就是同時提交兩個表單。

解決方案:
要同時提交兩個表單是不可能的,我們只能一次一次地提交,如果能夠做到提交其中一個表單時不重新整理頁面,也就做到了提交兩個表單了。不重新整理頁面,有兩種方法:
1.通過組件 Msxml2.XMLHTTP
   http://blog.csdn.net/loveyon/archive/2005/05/25/380826.aspx
  問題:只能提交文字框,對於上傳檔案等就不適應了。
2.通過iframe
  先讓第一個表單提交到該iframe,把第一個表單的target指向iframe的name就可以了。再在iframe中通過javascript提交第二個表單。
   也可以解決上述問題。

代碼示範:

<!-- 指定iframe 的name -->
<iframe width=100% height="100" scrolling="Auto" name="iframe" src="about:blank"></iframe>

<html:form action="提交表單到iframe" enctype="multipart/form-data" target="iframe">
  <html:file property="theFile"/>
  <html:submit/>
</html:form>

<html:form action="提交表單2 " target="iframe">
  <input type="text" name="test" value="中國一定強"/>
</html:form>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.