0
Guys, I have a code where I receive JSON data, but when I show it is as Undefined.
function usuario_search(id){ $.ajax({
type:"GET",
url: "/usuarios/search/"+id,
success: function(data) {
console.log(data);
var json = JSON.parse(data);
console.log(json);
alert(data);
document.getElementById('name').value = json.name;
document.getElementById('email').value = json.email;
document.getElementById('permission').value = json.role;
$('#defaultModal').modal('show');
},
error: function(ts){
$("#error").text(ts.responseText);
}});}
Alert with the data:
What appears in the modal:
Debugger:
puts a Debugger; and sees the return, depending on how it was done on the server it comes as return.data in your case would be date.
– Otto
edited the publication, look there
– Victor Gabriel
You have noticed that json is an array?
– Leonardo Bosquett
tried
document.getElementById("name").value = json[0].name;
?– Leonardo Bosquett
@Leonardobosquett Thank you so much! I got it, I’m starting Ajax, but thank you so much.
– Victor Gabriel