0
Hello
I’m creating a json and in each json information I need to put an image but I didn’t want a giant code so I don’t want to use Base64 there is some way to put a link in the json that leads to an image?
The image in json will pass a javascript filter so I don’t know if I can put the image url in the img tag.
[
{
"titulo": "Texto titulo",
"localizacao": "Texto localização",
"texto": "Texto grande de exemplo para usar como teste geral",
"imagem": "",
"id": 0
}
]
Editing
[
{
"titulo": "Teste 1",
"imagem": "imagens/Exemplo.png",
"id": 0
},
{
"titulo": "Teste 2",
"imagem": "imagens/sardinha11.png",
"id": 1
}
]
<img class="imageminfo" id="imagemareas" src="imagens/Exemplo.png">
I put it that way and then my script has a function and at the end of it I use this form to edit the image:
var image: obj.imagem;
$("#imagemareas").text(this.image);
The script is not complete because there are different scripts of this genre that I don’t think and need to present or the question would get too big.
Answer
With the help of some answers I managed to realize my solution:
[
{
"titulo": "1",
"imagem": "./imagens/Exemplo.png",
"id": 0
},
{
"titulo": "2",
"imagem": "./imagens/sardinha11.png",
"id": 1
}
]
var image: obj.imagem;
$("#imagemareas").attr("src", this.image);
<img class="imageminfo" id="imagemareas" src="">
yes, in json just use
"imagem": "http://algumdominio/imagem.jpg"
, then just set thesrc
image with the link– Ricardo Pontual
@Ricardopunctual but http leads to an image on the pc?
– David Mv
if u want a local image should put in question to help. In the case of local image can use the relative path:
src=image.jpg
orsrc=../imagems/imagem.jpg"
– Ricardo Pontual
@Ricardopunctual still not working there is some way I can share my code so you can take a look to see what’s going on?
– David Mv
you can edit the question and put here, also helps other people understand and propose other solutions :)
– Ricardo Pontual
I have already solved thanks I will put the solution in the question
– David Mv