I have the following ajax request…
Ajax
function initUpdate()
{
var id = $(this).attr('id').split('_')[1];
//grab id from link update_xxxx
//get all gallery information
$.ajax(
{
type: 'POST',
url: 'ajax/update',
data: {"id": id},
dataType: 'json',
success: function(json)
{
//query was successful now populate form
$("input[name='galleryName']").val(/*what goes here?*/);
}
});
}
That returns the following data
{
"selected_gallery": [
{
"id": "4004",
"name": "Album Proofer Sample Gallery",
"clientRef": "205",
"clientName": "Mike "
}
]
}
How would I access “name” to insert in the val()?
Thanks!
What have you tried? I would think you could get to it via:
selected_galleryis a JavaScript array, so you would access the first item in the collection using[0]in order access the first item’s properties.UPDATE
You could access other items in the array if they existed:
To get the second item in the array, you’d reference it as:
json.selected_gallery[1].name(oridorclientRefor …). You can get to the third item viajson.selected_gallery[2].name.Hope this helps.