4
I tried to make a mini database in JSON:
[
{
"titulo": "Exemplo",
"localizacao": "Rua de Exemplo",
"texto": "Texto grande de exemplo para usar como teste"
}
]
Then I created a general variable for JSON to use JSON in a separate file:
function LoadJsonData() {
var jsondata;
$.ajax({
url: './Json/JsonSite.json',
dataType: 'json',
async: false,
success: function (json) {
jsondata = json;
}
});
return jsondata;
}
but I have a problem.
I wanted to write the title that is in JSON, the location and the text in my HTML, but it is not writing.
var json = LoadJsonData();
document.getElementById("tituloareas").innerHTML = json[1].titulo;
document.getElementById("localizacaoareas").innerHTML = json[1].localizacao;
document.getElementById("textoareas").innerHTML = json[1].texto;
<div class="informacaodasareas">
<h2 class="tituloinfo" id="tituloareas"></h2>
<p class="localizacaoinfo" id="localizacaoareas"></p>
<h5 class="textoinfo" id="textoareas"></h5>
<div class="imageminfo" id="imagemareas"></div>
</div>
json[1]? would not json[0]?
– Ricardo Pontual
@Ricardopunctual changed to json[0] and nothing changed
– David Mv
after that line
var json = LoadJsonData();
can display the content that returned in the json variable?– Ricardo Pontual
@Ricardopunctual I put everything I created to var json e defeni that would be equal to function that this in another file! tas to realize this is my script I think is missing something to activate the Document
– David Mv