Ok, I'm sure this is simple but I'm not jquery expert. I have an ajax call that has an array returned as a variable. I'm having trouble accessing that array.
Here is what I want to do.
My array is setup so that the key matches the id of an input on my page. I want to traverse through my inputs and if there is a key that matches the id of the input, set the value of that input to the value of what's in the array. So here is what I have so far:
function populateFields(table_name, user_id, div){
$.ajax({
data:{
mode:'getInfo',
table_name: table_name,
user_id: user_id
},
url:'my_page.php',
type: "POST",
dataType: "text",
success:function(data){
data=$.parseJSON(data);
if(data.error != undefined){
if(data.error !== false){
showError(data.error);
} else {
var inputName="";
$('#'+div+' > input').each(function(){
inputName=$(this).attr('id');
/*Check to see if inputName is a key and if so, set the value of this input to the value matching the key*/
});
}
} else {
showError('The script was not called properly, because data.error is undefined.');
}
},
complete:function(){
}
});
}
The name of the variable being returned is called info. So data.info is the object with the information.
In the debugger data.info has this setup:
Object 2: Object agreed:"no" city: null email: "email@email.com"
Any idea what the code would be between the /* */ marks?