0

So I've been fighting this issue for a few days now and I still can't figure out why this global variable doesn't seem to retain the changed value between function calls..

I've also tried adding window.Client_Model = {} and then calling window.Client_Model with the same results.

var Client_Model = {};

// after page loads
$(document).ready(function() {
    get_server_model();
    $("#demohi").text(JSON.stringify(Client_Model)); //outputs blank dictionary
    //get_page_elements();
    //send_graph_data();
});


function get_server_model(){
    $.post( "/get_server_model", {
      "cmd": "GET_SERVER_MODEL"
    }, function(resp){

        var response = JSON.parse(resp);

        if (response.error === true)
        {
            alert("Error");
        }
        else
        {

            Client_Model = response.server_model;
            set_page_elements(response.server_model);
            $("#demolow").text(JSON.stringify(Client_Model.graph_lines)); // correct output
        }
    });
}
johnnyX
  • 75
  • 1
  • 7
  • 1
    Between which function calls, specifically, does the value not get retained? Are you looking for a way to store the value between _page loads_? Then see [Persist variables between page loads](/q/29986657/4642212). Do you expect to use the populated `Client_Model` outside of the `$.post` callback? Then see [Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference](/q/23667086/4642212). – Sebastian Simon Aug 29 '21 at 14:18
  • Sorry, forgot to add comments to show my output. It's the second case I'm interested in. – johnnyX Aug 29 '21 at 14:21

0 Answers0