Chrome 中使用 iframe 目标的跨域表单发布
我有一个表单可以发布到隐藏的 iframe。表单的操作 URL 位于单独的域中。我在 Chrome 中看到一个问题,表单已发布,但没有发送表单数据。
设置如下:
<form action="http://anotherdomain/save" method="post" target="myiframe" id="myform">
<!-- standard form fields here -->
<button type="submit">Submit</button>
</form>
<iframe src="about:blank" name="myiframe" style="display: none;"></iframe>
如果用户单击该按钮,表单将按其应有的方式发布到 iframe 中,一切正常。但是,如果我引入 jQuery 验证,Chrome 中的事情就会停止工作。我的验证如下所示:
$("#myform").validate({
// various options set here
submitHandler: function(form) {
form.submit();
// stuff that should happen after the form submits
}
});
在这种情况下, form.submit() 导致表单提交而不发布任何数据,仅发送标题。内容长度始终为 0。这只发生在 Chrome、Firefox、IE、Opera 中,所有提交都正常。
更奇怪的是,如果我在页面上有另一个按钮并使用以下代码将其连接,则表单会正确提交。
$("myotherbutton").click(function() { $("#myform").submit(); }
我不知道为什么 Chrome 会这样,以及是否有解决方法。任何帮助将不胜感激。
I have a form on that posts to a hidden iframe. The form's action URL is on a separate domain. I'm seeing a problem in Chrome where the form posts, but no form data is sent.
Here's the setup:
<form action="http://anotherdomain/save" method="post" target="myiframe" id="myform">
<!-- standard form fields here -->
<button type="submit">Submit</button>
</form>
<iframe src="about:blank" name="myiframe" style="display: none;"></iframe>
If the user clicks the button, the form posts as it should into the iframe and all is good. If, however, I introduce jQuery Validation, things stop working in Chrome. I have my validation looking like this:
$("#myform").validate({
// various options set here
submitHandler: function(form) {
form.submit();
// stuff that should happen after the form submits
}
});
In this scenario, form.submit() causes the form to submit without any data being posted, only the headers are sent. The content-length is always 0. This only happens in Chrome, Firefox, IE, Opera all submit fine.
What's more strange is if I have another button on the page and I wire it up with the following code, the form submits properly.
$("myotherbutton").click(function() { $("#myform").submit(); }
I'm at a loss as to why Chrome behaves this way, and if there is a workaround. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请忽略这个问题。这不是 Chrome 和事件处理程序的问题,而是与在调用事件之前删除 DOM 元素有关的问题。
Please ignore this question. It was not a problem with Chrome and event handlers, but rather one related to removing a DOM element before an event was called on it.