I have to send some parameter to an IFRAME with POST method. I have read here Setting the HTTP request type of an <iframe> that it isn't possible. I'm thinking a solution in Javascript but I can't implement it so I can't test if it is a valid solution for this issue. I want to ask if someone has the same problem and if it is possible to solve and in positive case how to?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
<form ... target="hidden_iframe">
...
</form>
<iframe name="hidden_iframe" ...></iframe>
回答2:
How about using the target attribute of the form to point to 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>
回答3:
Just to give a concrete working example
<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>