Matthew Smart
Matthew Smart

Reputation: 1319

How to use ajax response JSON data?

I have made my ajax request, which works great and returns JSON.

But how do i use it?

My response is something like this

[{
    "id": "5",
    "reviewID": "2389",
    "serviceID": "50707",        
    "title": "well done"
}]

Now in my success function I am trying to use the data like such:

success: function(data) {
    alert('Success Alert');
    $('#myModalLabel').text('Review:' + data.title);
},

This just shows

[object Object] 

How can I use this data?

Upvotes: 4

Views: 932

Answers (1)

Tushar
Tushar

Reputation: 87203

As data is array of objects, use data[0].title:

$('#myModalLabel').text('Review:' + data[0].title);
//                                      ^^^

Upvotes: 10

Related Questions