Created
December 15, 2016 08:26
-
-
Save havran/319c8238ed27749a17a1be9004d936dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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