-3

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 could I add the content of json result to fill this empty var?

var address = ?????
var client_name = ?????
Deden Bangkit
  • 598
  • 1
  • 5
  • 19

1 Answers1

1
$.ajax({
         type: 'POST',
         ....
         ....
         dataType: 'json', // don't forget !!!
         success: function(data) {
                      var address = data.result.address;
kevin ternet
  • 4,514
  • 2
  • 19
  • 27
  • Thanks, this is works for me. Also the developer said that it may use jsonp since cross origin request. Should I do something else? – Deden Bangkit Oct 25 '16 at 15:55
  • 1
    JSONP is an extension of JSON to get rid of cross-domain restrictions. You'll have to load script as JSON + a callback function. But unfortunately, I'm far for being an expert of JSONP. I advice you : http://stackoverflow.com/questions/2067472/what-is-jsonp-all-about – kevin ternet Oct 25 '16 at 16:19