Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// See, jQuery version with arrays and objects support
function post(path, parameters) {
var form = $('<form></form>');
form.attr("method", "post");
form.attr("action", path);
$.each(parameters, function(key, value) {
if ( typeof value == 'object' || typeof value == 'array' ){
$.each(value, function(subkey, subvalue) {
var field = $('<input />');
field.attr("type", "hidden");
field.attr("name", key+'[]');
field.attr("value", subvalue);
} else {
var field = $('<input />');
field.attr("type", "hidden");
field.attr("name", key);
field.attr("value", value);

This comment has been minimized.

Copy link

@StephanWeinhold StephanWeinhold commented Jan 29, 2016

I'd use var post = function as every function in JS is a variable.

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