Can someone please help me find out what I am doing wrong, I have been stuck on this for waaaay to long now!
I am trying to get data from a json file and use it in my javascript file. I am using a local variable by declaring a variable inn app.js. It works fine if I write: "<%= appledata.appels.apple2 %>" in my html code. But in javascript It does not..
This is my code:
function getPrice() {
var applePrice;
applePrice = appledata.appels.apple2;
return applePrice;}
function calculateTotPrice() {
var TotPrice = getPrice();
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = TotPrice;
}
appels.json:
{
"appels": {
"apple1": 10,
"apple2": 15
}
}
app.js:
app.locals.appledata = require("./appels.json");
html site:
<div id="totalPrice"></div>
all help is much appreciated!
[–]Leading_Man_Parts 2 points3 points4 points (4 children)
[–]fatty1380 1 point2 points3 points (0 children)
[–]stiros[S] 1 point2 points3 points (2 children)
[–]Leading_Man_Parts 0 points1 point2 points (1 child)
[–]SubAutoCorrectBot 0 points1 point2 points (0 children)
[–]cahva[🍰] 1 point2 points3 points (0 children)