To read properties on the data
object, data.startDate
and data["startDate"]
should both work.
As pointed out by jaywon, the problem is that your data object is a string, not an object. You can confirm this by adding another console.log
line, like this:
console.log(typeof data);
That will print out "string" instead of "object". You can print out properties of the string object in the normal way, for example the number of characters is:
console.log(data.length);
To get jQuery to parse the JSON for you, you need to either set the dataType property as described by jaywon, or include this content-type header when you serve up your json:
Content-Type:text/json
If you include this header from the server, then you're example code will print the correct properties to the console.
Finally, to add a row to your table, you need to append a table row instead of a plain text string, so you should change your var tr = ...
line to this:
var tr = '<tr>' +
'<td>' + data.startDate +'</td>' +
'<td>' + data.active +'</td>' +
'<td>' + data.currentPrize +'</td>' +
'</tr>';