[Solved] Chrome submission error: Form submission canceled because the form is not connected

The code that ran normally in Chrome before, and the report submission error after Chrome was upgraded to 56:

Form submission canceled because the form is not connected

code show as below:

function submitData(name) {
  var form = $('<form method="post" action="updateName">'
                +'<input type="submit"/>'
                +'<input type="hidden" name="name" value="'+ name +'" /></form>');
 
  $('input[type="submit"]', form).click();
}
problem solved

the reason

The HTML standard stipulates that if the form is not added to the document, the form submission will be terminated.

Reference: Form submission algorithm

The version before Chrome56 is not compliant with the standard. Chrome56 fixes this problem and makes the form submission meet the standard requirements:

Reference: Chrome issue 2416033002

 

Solution

The solution is to add the form to the document before submitting:

jQuery

$(document).append(form);

or

document.body.appendChild(form);

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *