Deden Bangkit Deden Bangkit - 1 month ago 8
Javascript Question

Parse Json from API to Javascript

I have attached API on my javascript which has this result when I posted via postman:

{"result": {
"clientId": 1,
"session": "yJZdWRhIjoiSEExMDA4MzAyMCJ9.wrBz8JpNqMZlqv8Pz2Tx1x-XYecfdsH2B5uTbNPfiQE",
"client name": Andrew,
"address": [
["1","Bandung","West Java","Indonesia"],
["2","Depok","West Java","Indonesia"]
}
}


and here's the API script:

var content='';
$.ajax({
type: "POST",
url:
rest_url+
'update/yJZdWRhIjoiSEExMDA4MzAyMCJ9.wrBz8JpNqMZlqv8Pz2Tx1x-XYecfdsH2B5uTbNPfiQE/'+_ClientId,
success: function (data) {
_Client = data;

}
});


How do I push the content of json data to fill this empty var?

var address = ?????
var client_name = ?????

Answer
$.ajax({
         type: 'POST',
         ....
         ....
         dataType: 'json', // don't forget !!!
         success: function(data) {
                      var address = data.result.address;