jQuery JSON Passing / Looping Issue
Hi All,
My ajax function passes back the following JSON STRING
Code:
[{"Contact":{"first_name":"Jack","last_name":"May"}},{"Contact":{"first_name":"Jane ","last_name":"May"}},{"Contact":{"first_name":"Jack","last_name":"May"}},{"Contact":{"first_name":"Margaret","last_name":"May"}}]
How do I go about looping through the results? This is what I have but it's not working.
Code JavaScript:
function populateNameOptions(data)
{
var themessage = 'We already have the following names in the database with the same last name: ';
// LOOP THROUGH THE RESULTS
// ----------------------------------------------------->
$.each(data.results, function(i,contact){
// this is where we do what we want with the results
themessage += contact.first_name + ' ' + contact.last_name + ', ';
});
$('#nameNotice').html(themessage);
}
Thanks