poorpaddy
(Dave)
December 7, 2016, 10:35pm
#1
Looking for a simple example of loading text & images from a json file. I’ve searched the forums a lot and nothing that was strictly just that.
For example I’d like to load the following json. Let’s call it animation-text.json.
{
"mydata" : {
"block-a" : {
"text-1" : {
"option-0": "Dude",
"option-1": "Awesome",
"option-2": "Bogus",
"option-3": "WTF",
"option-4": "Strange"
},
"title" : "Click bait stinks",
"subtitle" : "I've got nothing!"
},
"block-b" : {
"text-1" : {
"option-0": "Dude",
"option-1": "Awesome",
"option-2": "Bogus",
"option-3": "WTF",
"option-4": "Strange"
},
"title" : "Thought of something new",
"subtitle" : "Still have nothing.",
"graphic" : "./images/fielname.png"
}
}
}
Then how would I apply values to different elements?
If someone could share an example file, that would be of huge help. I do well with reverse engineering.
1 Like
h_classen
(Hans-Gerd Claßen)
December 8, 2016, 6:37am
#2
there’ll be tons of examples doing a forum search.
Perhaps you can point one out that is helpful? I’ve read a bunch and this seams to be you’re standard response on each. These forums are all that intuitive to search either.
h_classen
(Hans-Gerd Claßen)
December 8, 2016, 7:13am
#4
var request = new XMLHttpRequest();
request.open('GET', '/my/url/animation-text.json', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var obj = JSON.parse(request.responseText);
var titleA = obj.mydata.block-a.title;
hypeDocument.getElementById('yourHypeElementsId').innerHTML = titleA;
} else {
}
};
request.onerror = function() {
};
request.send();
4 Likes
Thank you. That worked perfectly.
hemal
(hemal)
July 24, 2018, 5:23am
#6
This post was flagged by the community and is temporarily hidden.
1 Like
petester
(Peter Borokhov)
July 10, 2020, 7:42pm
#7
Thats exactly what Im looking for, an example of how to load up to 9 boxes or selections pulling an image, price... via a JSON file.
Daniel
July 10, 2020, 8:02pm
#8
Seems like you found it? Hans answered above: Load text from JSON
This is the same whether you're doing this in our outside of Hype, the only difference between loading this result in a regular HTML element is in Hans' code you're placing the result in a Hype element (this line):
hypeDocument.getElementById('yourHypeElementsId').innerHTML = titleA;