im making a table for a management system interface, and the way the table gets its data is from mysql and the other is fetched from json file, the std data fetched from the json file is assigned to ID_Recording. The problem seems to be that the std subcolumns being empty is likely due to how the data is being fetched and rendered in my frontend JavaScript code, but i cant seem to figure out why
dashboardreports.js
// Handle GET request to fetch standard values from JSON file
app.get('/standardValues', (req, res) => {
fs.readFile(path.join(__dirname, '..', 'views', 'standardValues.json'), 'utf8', (err, data) => {
if (err) {
console.error('Error reading standard values:', err);
res.status(500).send({ message: 'Error reading standard values', error: err });
} else {
let standardValues = JSON.parse(data);
console.log('Standard Values:', standardValues);
res.json(standardValues); // Send standard values as JSON response
}
});
});
dashboardreportsscript.js
// Fetch standard values function
function fetchStandardValues() {
fetch('/standardValues')
.then(response => {
if (!response.ok) {
throw new Error('Failed to fetch standard values');
}
return response.json();
})
.then(data => {
console.log(data); // Check if standard values are fetched correctly
standardValues = data; // Update the global standardValues array
fetchLatestData(); // Call fetchLatestData after fetching standard values
})
.catch(error => console.error('Error fetching standard values:', error));
}
standardValues.json
[
{
"ID_Recording": "1",
"Average_Daily_Gain": 1.20,
"Food_Conversion_Ratio": 1.50,
"Berat_Ayam": 2.20,
"Jumlah_Deplesi": 1.1
},
{
"ID_Recording": "2",
"Average_Daily_Gain": 1.30,
"Food_Conversion_Ratio": 2132.60,
"Berat_Ayam": 2.30,
"Jumlah_Deplesi": 1.2
},
etc…
i did try to log it, and the data came perfectly clear in developer tools console without any errors, but not in the interface tables…
Munif Fachrudin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.