简体   繁体   English

通过iframe跨域表单提交,无需服务器端控件

[英]Cross domain form submission via iframe, without server side controls

I'm attempting to set up a same-page form submission mechanism for a client website. 我正在尝试为客户网站设置同页表单提交机制。 Their forms submit to a handler page which is on a different domain, so I cannot submit via ajax. 它们的表单提交到另一个域上的处理程序页面,因此我无法通过Ajax提交。 Previously I have had success cloning my form into an iframe and submitting that (I don't need to retain control of the iframe, and I don't need to verify receipt, just post the data) but that is now being blocked in Chrome. 以前,我已经成功地将表单克隆到iframe中并提交了(我不需要保留对iframe的控制,也不需要验证收据,只需发布​​数据即可),但是现在在Chrome中被屏蔽了。

It would be relatively trivial to add cross-domain headers if I had control of the servers involved, but I don't. 如果我可以控制所涉及的服务器,则添加跨域标头相对来说并不容易,但是我没有。

Is there any way to resolve this, or do I have to tell my client that the method I was using is no longer available and they have no options without making server-side changes? 有什么方法可以解决此问题,还是我必须告诉客户端我正在使用的方法不再可用,并且如果不进行服务器端更改,他们将没有选择权?

There's no need to clone the form. 无需克隆表格。 Just set target="iframe_name" on the <form> element. 只需在<form>元素上设置target="iframe_name"

Just target the iframe. 只需定位iframe。 You can change form's target and action dynamically, if for example you need to reuse it for some other submission. 您可以动态更改表单的目标和操作,例如,如果需要将其重新用于其他提交。

<form target="IFRAME_NAME">...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM