So my problem is the next one:
I'm trying to get text from a JSON file, on my html on the header I linked a tag that has:
var language = "";
var langDoc = null;
//Function to change the value
function setLang() {
var myCookie = getCookie("language");
if (myCookie == null) {
document.cookie = "language=español";
language = "español";
$.getJSON("/lenguajes/" + language + ".json", function(data) {
langDoc = data;
});
}
else {
language = myCookie;
$.getJSON("/lenguajes/" + language + ".json", function(data) {
langDoc = data;
});
}
}
//Final function to get text from file
function getTextFromJson(textToGet){
return langDoc[textToGet];
}
And I'm trying to call the setLang(); function before calling my getTextFromJson() one, to get the text from the modified variable, but when I do it, the functions says that can't get the property "IDIOMA" from null, so the variable is not changing, the HTML looks like this:
<script type="text/javascript"> setLang(); </script>
<script type="text/javascript"> alert(getTextFromJson("IDIOMA")); </script>
<!-- other HTML -->
And the idea is to be able to use that method on other parts of the HTML to make a multilanguage page
Thank you!