This is my code:
$(document).ready(function() {
$(document).on("click", ".audioButton", function() {
var word = $(this).parent().find('.exerciseWord').html().toLowerCase() + '.mp3';
play(word);
});
getFileArray(); // load on page load
});
function getFileArray(word) {
$.getJSON("https://test.diglin.eu/api/media/fileList", {
lang: param
})
.done(r => {
audioArray = r.audio;
console.log("audio data loaded");
if (word) play(word);
});
}
function play(word) {
if (!audioArray) getFileArray(word);
else {
var foundID = audioArray.lowercase.indexOf(word);
console.log("foundID", foundID);
if (foundID > -1) {
var audio = new Audio();
audio.src = 'http://test.diglin.eu/' + audioArray.path + audioArray.files[foundID];
audio.play();
}
}
}
The code I am trying to give to param
:
$.getJSON('json_files/jsonData_' + ID + '.json', function(json) {
var jsonDataLanguage = json.main_object.language;
}
how the JSON (with a unique ID) looks like:
{
"main_object": {
"id": "new",
"getExerciseTitle": "TestToConfirm",
"language": "nl_NL",
"application": "lettergrepen",
"main_object": {
"title": "TestToConfirm",
"language": "nl_NL",
"exercises": [
{
"word": "Hallo Marja.",
"syllables": [
"hallo",
"marja",
"",
""
]
}
]
},
"dataType": "json"
}
}
So the next thing should happen (but doesn't work when I try so):
I try to access the desired ID in my json file. There in my JSON file I have sent a language with aswell, and it should fetch that language and be the value of param
. I tried doing so, but it throws the error: "json is not defined". Most likely because I am not accessing a JSON file with a certain ID. how could I do this? I know this is the problem, but I don't know how to solve it.