Skip to content

Instantly share code, notes, and snippets.

@havran
Created December 15, 2016 08:26
Show Gist options
  • Save havran/319c8238ed27749a17a1be9004d936dc to your computer and use it in GitHub Desktop.
Save havran/319c8238ed27749a17a1be9004d936dc to your computer and use it in GitHub Desktop.
var createSubmitForm = function(path, parameters, method = 'POST') {
var form = $('<form></form>');
form.attr('action', path);
form.attr('method', method);
parameters.authenticity_token = $('meta[name="csrf-token"]').attr('content');
for (var key in parameters) {
if (parameters.hasOwnProperty(key)) {
var hiddenField = $("<input>");
hiddenField.attr("type", "hidden");
hiddenField.attr("name", key);
hiddenField.attr("value", parameters[key]);
form.append(hiddenField);
}
$('body').append(form);
form.submit();
form.remove();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment