Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 290
Matthew Smart Avatar asked Dec 24 '22 17:12

Matthew Smart


1 Answers

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

$('#myModalLabel').text('Review:' + data[0].title);
//                                      ^^^
like image 115
Tushar Avatar answered Dec 27 '22 12:12

Tushar