Last active
March 31, 2020 19:16
-
-
Save cgiovanii/9debf6c39b70365a4706366dee6b2d80 to your computer and use it in GitHub Desktop.
Function to convert serialized data from form to json format #JS
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
// 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