function Setup () {
var URL = 'http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Diagonal_Line.json';
fetch(URL)
.then(res => res.json())
.then(data => {
// To display just the name in the textbox
document.getElementById("Data_Text").value = data.Diagonal_Lines[Diagonal_Line_1][0].First_X1_Coordinate;
// Or, if you want to show the whole JSON object as a string:
// document.getElementById("JSON_Text").value = JSON.stringify(data);
});
}
Then the console told me that Diagonal_Line_1 is undefined. And I don’t know where I went wrong.
I seem to be improving, but I’m still running into glitches. My Javascript now looks like this:
function Setup_2 () {
var URL = 'http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Diagonal_Line.json';
fetch(URL)
.then(res => res.json())
.then(data => {
console.log(data);
// To display just the name in the textbox
document.getElementById("Data_Text").value = data.Diagonal_Lines.Diagonal_Line_1[0].Second_Y1_Coordinate;
// Or, if you want to show the whole JSON object as a string:
// document.getElementById("JSON_Text").value = JSON.stringify(data);
});
}
I can access any part of the Diagonal_Line_1 array. But I can’t access any of the Diagonal_Line_2 array. I don’t know why this is happening. Any sugestions?
function Setup () {
var URL = 'http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Diagonal_Line.json';
fetch(URL)
.then(res => res.json())
.then(data => {
console.log(data);
// To display just the name in the textbox
document.getElementById("Data_Text").value = data.Diagonal_Lines.Diagonal_Line_2.First_X1_Coordinate;
// Or, if you want to show the whole JSON object as a string:
// document.getElementById("JSON_Text").value = JSON.stringify(data);
});
}
And I had to make a couple of adjustments to my JSON document: