I am using Ajax to return my object. I did a console.log(obj) and my object seems perfect. This is how it looks in my console log :
[{"first_name":"jeremiah", "last_name":"test"}, {"first_name":"jay", "last_name":"grens"}]
However, when I come to append each first_name and each last_name to a specific div, I can't make it work. This is how my Ajax looks like :
$('#search_contact').keyup(function() {
var keys = $(this).val();
$.ajax({
type: 'post',
url: 'contacts/search',
data: {'keys':keys},
success: function(res) {
console.log(res);
$('#contacts tbody').html('');
$.each(res, function(i, val) {
$('#contacts tbody').append('<tr><td>'+first_name+'</td><td>'+last_name+'</td></tr>');
});
}
});
});
When I do this, my #contacts tbody is empty, and I get this error in my console log :
Uncaught TypeError: Cannot use 'in' operator to search for '926' in (my full obj...)