Skip to content

Instantly share code, notes, and snippets.

@kenmori
Last active March 28, 2017 05:32
Show Gist options
  • Save kenmori/0fabfa855ac496badbc1ee8c9a5e9bb2 to your computer and use it in GitHub Desktop.
Save kenmori/0fabfa855ac496badbc1ee8c9a5e9bb2 to your computer and use it in GitHub Desktop.
【Android/ (Chrome/56.0.2924.87)】how to fix 「Form submission canceled because the form is not connected」
//An error occurs //The form will be canceled. On Android/Chrome/56.0.2924.87
$("<form />", { action: "/hoge/fuga", method: "post" })
.append($("<input />", { type: "hidden", name: "xtoken", value: xtoken }))
.append($("<input />", { type: "hidden", name: "state", value: "/hoge/" + hogeId }))
.append($("<input />", { type: "hidden", name: "hoge", value: hoge }))
.append($("<input />", { type: "hidden", name: "back", value: location.pathname }))
.submit();
/////
//// add .appendTo(document.body), before .submit()
////
/// fix
$("<form />", { action: "/hoge/fuga", method: "post" })
.append($("<input />", { type: "hidden", name: "xtoken", value: xtoken }))
.append($("<input />", { type: "hidden", name: "state", value: "/hoge/" + hogeId }))
.append($("<input />", { type: "hidden", name: "hoge", value: hoge }))
.append($("<input />", { type: "hidden", name: "back", value: location.pathname }))
.appendTo(document.body).submit();
//if not using jQuery, using JS,
//after appendChild(form) value, finaly,
document.body.appendChild(form);
form.submit();
@toshimaru
Copy link

Thanks <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment