So I get these numbers from a JSON file:
var homePoints = game.total_points_bet_on_hometeam;
var awayPoints = game.total_points_bet_on_awayteam;
but later on in my code I use an ajax call to submit new numbers and retrieve the new JSON numbers. How would I go about changing homePoints and awayPoints to the new numbers from my ajax call?
I looked over the answers I was given and none of them seem to match what I'm trying to do. Right now the variable that I need to replace the number in is inside another function that is calling the JSON.
         $.each(gameData, function(key, game){
            var homePoints = game.total_points_bet_on_hometeam;
            var awayPoints = game.total_points_bet_on_awayteam;
            var totalPoints = homePoints + awayPoints;
            var myChart = new Chart(ctx, {
                  type: 'doughnut',
                  data: {
                    labels: [homeShort, awayShort],
                    datasets: [{
                      backgroundColor: [
                        homeColor,
                        awayColor
                      ],
                      data: [homePoints, awayPoints]
                    , borderWidth: 0
                    }]
                  },
                  options: {
                        responsive: true
                    ,   maintainAspectRatio: true
                  }
                });
               };
$.ajax({
              url: "---------/dbdata/bet/new/" + userId + "/"+ gameId +"/"+ id +"/"+ value +"",
              type: "get",
            success: function(response) {
                function update(){
                var currentSelection = $('#team-select').val();
                    getGames().done(function(results){
                        $.each(results, function (i, gameData){
                            $.each(gameData, function(key, game){
                                    var gamesId = game.id;
                                    // clears the current bet totals and replaces them with new ones.
                                    if(gameId === gamesId){
                                        var totalPointsHome = this.total_points_bet_on_hometeam;
                                        var totalPointsAway = this.total_points_bet_on_awayteam;
                                        var homePoints = this.total_points_bet_on_hometeam;
                                        var awayPoints = this.total_points_bet_on_awayteam;
                                        var totalPoints = homePoints + awayPoints;
                                        console.log(homePoints)
                                        $('#' + gameId + ' .total-points').empty();
                                        $('#' + gameId + ' .total-points').append( totalPointsAway + totalPointsHome);
                                    }
                            });
                        });
                    })
                }
                update();
 
    