簡體   English   中英

如何使用 HTTP POST 請求將參數發送到 Iframe

[英]How to send parameter to Iframe with a HTTP POST request

我必須使用 POST 方法向 IFRAME 發送一些參數。 我已閱讀此處設置不可能的 <iframe> 的 HTTP 請求類型 我正在考慮 Javascript 中的解決方案,但我無法實現它,所以我無法測試它是否是解決此問題的有效解決方案。 我想問是否有人有同樣的問題,是否有可能解決,在積極的情況下如何解決?

<form ... target="hidden_iframe">
...
</form>

<iframe name="hidden_iframe" ...></iframe>

用表單的target屬性指向iFrame怎么樣?

 <form target="myIframe" action="http://localhost/post.php" method="post">
    <input type="hidden" value="someval" />
    <input type="submit">
</form>

<iFrame src="" name="myIframe"></iFrame>

只是舉一個具體的工作例子

<form id="loginForm" target="myFrame"  action="https://localhost/j_spring_security_check" method="POST">
 <input type="text" name="j_username" value="login" />
 <input type="text" name="j_password" value="password" />
 <input type="submit">
</form>

<iframe name="myFrame" src="#">
   Your browser does not support inline frames.
</iframe>

// Hide the form and do the submit 
<script>
 $(document).ready(function(){
 var loginform= document.getElementById("loginForm");
 loginform.style.display = "none";
 loginform.submit();
});
</script>

在我的情況下,建議的解決方案幾乎可以正常工作,問題是我的表單提交返回了授權 cookie。 呈現 iframe 的網站位於 iframe 網站的不同域中,此方法返回我無法設置 cookies 的錯誤。 有沒有安全的方法來解決這個問題?

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM