I'm trying to recover the values that passed through an array in json to ajax.
this is the code I use:
function CompletarEan(cod) {
$.ajax({
url: "./Scripts/Phps/Autocompletar.php?pag=autocompletar_Ean&term="+cod,
type: "post",
dataType: 'json',
success: function(data) {
$("#InAlbaran_Articulo").val(data.idean);
$("#InAlbaran_Ean").val('');
console.log(data.idean);
},
error: function(xhr, status, error){ $().toastmessage('showToast', { text : 'Error con ean '+ xhr.responseText, sticky : true, type : 'error' }); }
});
}
and this is the array that json returns to me:
[{"idean":"1316","nombre":"843446300058"}]
The fact is that I would like to assign those values received to different input but I do not know why it results in undefinied.
What can I be doing wrong? or how are the values in ajax recovered?