Skip to content

Instantly share code, notes, and snippets.

@cgiovanii
Last active March 31, 2020 19:16
Show Gist options
  • Save cgiovanii/9debf6c39b70365a4706366dee6b2d80 to your computer and use it in GitHub Desktop.
Save cgiovanii/9debf6c39b70365a4706366dee6b2d80 to your computer and use it in GitHub Desktop.
Function to convert serialized data from form to json format #JS
// Envia a encomenda para o mailer.
function serializeToJson(form) {
//Pega os dados do form serializa e converte para objeto
let data = $(form).serialize().split("&");
let dataObj = {};
for (var key in data) {
dataObj[data[key].split("=")[0]] = data[key].split("=")[1];
}
//Converte o objeto para json
let dados = JSON.stringify(dataObj)
return dados
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment