出现错误“表单提交被取消,因为表单未连接" [英] Getting Error "Form submission canceled because the form is not connected"

查看:27
本文介绍了出现错误“表单提交被取消,因为表单未连接"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 JQuery 1.7 的旧网站,它可以正常工作到两天前.突然,我的一些按钮不再起作用,单击它们后,我在控制台中收到此警告:

I have an old website with JQuery 1.7 which works correctly till two days ago. Suddenly some of my buttons do not work anymore and, after clicking on them, I get this warning in the console:

表单提交被取消,因为表单未连接

Form submission canceled because the form is not connected

点击背后的代码是这样的:

The code behind the click is something like this:

 this.handleExcelExporter = function(href, cols) {
   var form = $('<form method="post"><input type="submit" /><input type="hidden" name="layout" /></form>').attr('action', href);
   $('input[name="layout"]', form).val(JSON.stringify(cols));
   $('input[type="submit"]', form).click();
 }

Chrome 56 似乎不再支持这种代码了.不是吗?如果是,我的问题是:

It seems that Chrome 56 doesn't support this kind of code anymore. Isn't it? If yes my question is:

  1. 为什么会突然发生这种情况?没有任何弃用警告?
  2. 此代码的解决方法是什么?
  3. 有没有办法在不更改任何代码的情况下强制 chrome(或其他浏览器)像以前一样工作?

附言它也不适用于最新的 Firefox 版本(没有任何消息).它也不适用于 IE 11.0 &边缘!(都没有任何消息)

P.S. It doesn't work in the latest firefox version either (without any message). Also it does not work in IE 11.0 & Edge! (both without any message)

推荐答案

快速回答:将表单附加到正文中.

Quick answer : append the form to the body.

document.body.appendChild(form);

或者,如果你像上面一样使用 jQuery:$(document.body).append(form);

Or, if you're using jQuery as above: $(document.body).append(form);

详情:根据 HTML 标准,如果表单未与浏览上下文(文档)相关联,则表单提交将被中止.

Details : According to the HTML standards, if the form is not associated to the browsing context(document), the form submission will be aborted.

HTML SPEC 见 4.10.21.3.2

HTML SPEC see 4.10.21.3.2

在 Chrome 56 中,应用了此规范.

In Chrome 56, this spec was applied.

Chrome 代码差异见@@ -347,9+347,16 @@

Chrome code diff see @@ -347,9 +347,16 @@

P.S 关于您的问题 #1.在我看来,与 ajax 不同的是,表单提交会导致页面即时移动.
因此,显示已弃用的警告消息"几乎是不可能的.
我也认为这个严重的变化没有包含在功能更改列表中是不可接受的.Chrome 56 功能 - www.chromestatus.com/features#milestone%3D56

P.S about your question #1. In my opinion, unlike ajax, form submission causes instant page move.
So, showing 'deprecated warning message' is almost impossible.
I also think it's unacceptable that this serious change is not included in the feature change list. Chrome 56 features - www.chromestatus.com/features#milestone%3D56

这篇关于出现错误“表单提交被取消,因为表单未连接"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆