0
I have a form with several fields when, I have a function that when submitting the form captures the fields:
$('.form').submit(function () {
var dados = JSON.stringify(jQuery(this).serializeArray());
alert(dados);
return false;
});
the fields returned in data are:
[{"name":"razao_social","value":"INTELIDER"},
{"name":"nome_fantasia","value":"INTELIDER LTDA"},
{"name":"cpf_cnpj","value":"10.999.558/0001-86"},
{"name":"rg_insc_estadual","value":"132456789"},
{"name":"login","value":"gleyson"},
{"name":"senha","value":"123456"},
{"name":"confirma_senha","value":"S"}]"
but I need it to stay that way:
[
{
"razao_social": "INTELIDER",
"nome_fantasia": "INTELIDER LTDA",
"cpf_cnpj": "10999558000186",
"rg_insc_estadual": "132456789",
"usuario": {
"login": "gleyson",
"senha": "123456",
"ativo": "S"
},
}
]
Remembering that I need to remove one password confirmation of the first code and add the field active of the second example, to send this Json.
the empty ta return: [{"user":{}}], debugged by Chrome and realized that it does not enter into $.each(data, Function (i,obj) { obj[obj.name] = obj.value; }); , although the variable has content, also has no error.
– Gleyson Silva
I put an Alert inside this function and saw that it is going through the data array normally, and I see playing the values inside the obj, but I can’t read them in the obj.usuario = { login: obj.login, password: obj.password, active: obj.confirma_password };, they come empty
– Gleyson Silva