Your JSON file is an array containing a single object. Therefore, you need to take the properties from the first item in that array.
$.getJSON('Content/ApexData/MinMax.json').then(function(response){
var value = response[0];
Min = value.Min;
Max = value.Max;
});
Also bear in mind that the "A" in "AJAX" stands for "asynchronous". Your variables will not be assigned until the request to the server has been completed and the callback has executed. If you attempt to access them immediately after the
$.getJSON
call, they will not have been initialized yet.
$.getJSON(...).then(...);
console.log("Min", Min, "Max", Max);
You will potentially need to rewrite your code so that you don't try to access the variables before the AJAX request completes.
You may find it easier to use an
async
function:
async function - JavaScript | MDN[
^]
(async function(){
let response = fetch('Content/ApexData/MinMax.json');
if (!response.ok) {
let errorMessage = await response.text();
console.error(response.status, response.statusText, errorMessage);
alert("There was an error loading the min/max data.");
return;
}
let result = await response.json();
let value = result[0];
let Min = value.Min;
let Max = value.Max;
... Use min and max here...
})();