Skip to Main Content

DevOps, CI/CD and Automation

How to manage json data from API?

Neil JosephJul 29 2020 — edited Jul 30 2020

I am having trouble managing my data when calling API web services because the result of AJAX result comes in last. To have  a better picture, see code below:

this.variable = ko.observableArray();

this.getAPI = function(){

     $.getJSON("<api_url>", function(result){

          console.log("api result");

          this.variable(result);

     });
console.log("call api");

}

this.setTable = function(){
    this.getAPI();
   console.log(this.variable());
    console.log("set table");
}


CONSOLE:

call api
[ ]
set table
api result


Do you guys have any idea what is the proper way of doing this type of programming setup?

Comments
Post Details
Added on Jul 29 2020
1 comment
60 views