Skip to content

Instantly share code, notes, and snippets.

@joasgarcia
Last active August 29, 2015 14:07
Show Gist options
  • Save joasgarcia/d7b477d9cfb0a2fe330f to your computer and use it in GitHub Desktop.
Save joasgarcia/d7b477d9cfb0a2fe330f to your computer and use it in GitHub Desktop.
Uma forma de enviar para o server um JSON com os dados de um form
var formFilterReference = $("form")
var jsonString = convertFormToJSON(formFilterReference)
$("#otherForm #filterData").val(jsonString);
$("#otherForm").submit();
var convertFormToJSON = function(form){
var array = $(form).serializeArray();
var json = {};
$.each(array, function() {
json[this.name] = this.value || "";
});
return JSON.stringify(json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment