Reputation: 2465
I have a piece of javascript that uses ajax to get data from my database as such:
$.ajax({
url: 'getlog',
data: { id: calEvent.id},
dataType: "json",
success: function(data)
{
alert(data[id]);
}
});
If i just alert the 'data' object i get
[object Object]
The data I am getting back from the ajax request is structured like this:
I need to be able to get these fields to fill up an edit form (form already exists on my page and I know how to set the values of my edits but I can't access the data)
Upvotes: 2
Views: 2141
Reputation: 2582
data.id
and data["id"]
both should work. In your case you had data[id]
so it was trying to search id as a variable which returned undefined.
Upvotes: 2