3
I have several inputs in an HTML, where the Ids are correct. I want to search the value
of these inputs with these Javascript variables, but only the nome
takes the variable value! The rest of the inputs are empty:
$.ajax({
url: 'api/user/getSession',
type: 'POST',
success: function(data){
document.getElementById("nome").value = data.nome,
document.getElementById("perfil").value = data.perfil,
document.getElementById("empresa").value = data.perfil
}
});
Be clearer, once I understand what you want to do; and to be clearer, put at least the html of your pseudo form .
– Renan Borges
If you are using the
jQuery
, why usegetElementById
? It is easier to use the selector$('#nome').val(data.nome)
;– Wallace Maxters
where the inputs?
– Wallace Maxters
Pke does not place a console.log(data.d) and see if the result is coming correctly. or even an Alert.
– Marconi
The inputs are text? values are coming up on the date variable? to check send a console.log(data.profile)
– Renan Borges
It was already arriving ok! Thank you all and Wallace Maxters worked out yours. I am n00b in JS and jQuery
– Daniela Morais
@Danielamarquesdemorais welcome to Sopt, glad your question was answered, it would be interesting to record your experience, put your html code and js, explain your question, as soon as someone offers a solution and is valid to your problem, accept !
– Isvaldo Fernandes
@Danielamarquesdemorais You can also use $.each in your json return ->
$.each(data,function(chave, valor) { $('#' + chave).val(valor);
});
(Just a hint even..., in your case you use a key for 2 different fields, then would need some changes even...)– Rafael Withoeft
Are the ids correct? The value 'data.profile' is returning value?
– deFreitas
@deFreitas Yes. The solution was jQuery, thank you
– Daniela Morais