jQuery: extrating ajax returned JSON data for display

I’m having trouble extracting ajax-returned data in JSON format. Here is my code:

$('#ajax').submit(function(e){
		
		$.ajax({
			url: 'appajax',
			type: 'POST',
			data: { _date: $('.app_date').val() },
			dataType: 'json',
			success: function(info)
			{

				console.log(info);
			}
		});
		e.preventDefault();
	});

When i run this code the console shows:

[Object]
0: Object
attributes: Object
appointment_date: "2013-04-30"
appointment_time: "18:15:00"
created_at: "2013-04-19 23:14:16"
doctor_id: 2
id: 2
patient_id: 3
problem: "migraine"
status: "unseen"
updated_at: "2013-04-19 23:14:16"
__proto__: Object
exists: true
includes: Array[0]
original: Object
relationships: Array[0]
__proto__: Object
length: 1
__proto__: Array[0]

… and im able to see the object and all attributes. But when I go to console.log(info.appointment_date) for example, the console shows ‘undefined’. What Im I missing? Or indeed how can I access individual attributes?

I also tried this code inside the success method:

$.each(info, function(key, val) {
					console.log(val);
				});

and it returns:

Object {attributes: Object, original: Object, relationships: Array[0], exists: true, includes: Array[0]}
attributes: Object
appointment_date: "2013-04-30"
appointment_time: "18:15:00"
created_at: "2013-04-19 23:14:16"
doctor_id: 2
id: 2
patient_id: 3
problem: "migraine"
status: "unseen"
updated_at: "2013-04-19 23:14:16"
__proto__: Object
exists: true
includes: Array[0]
original: Object
relationships: Array[0]
__proto__: Object

And still im unable to extract the data. What do i do? Thanks

Hi there,

instead of:

console.log(info.appointment_date)

try:

console.log(info['appointment_date'])

or failing that:

console.log(info[0]['appointment_date'])

Does that work?

The last option works perfectly i.e.

console.log(info[0]['appointment_date'])

Many thanks…

You’re welcome.
Thanks for taking the time to report back :slight_smile: