Jeremy C.
Jeremy C.

Reputation: 2465

jquery ajax post data undefined

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:

enter image description here

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

Answers (1)

Amar Kamthe
Amar Kamthe

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

Related Questions