I’m more of a backend guy, this javascript stuff is a bit out of my area. I could really use a point in the right direction 🙂
So I have an URL that, for example, returns this JSON:
[{"pk": 1, "model": "didyouknow.fact", "fields": {"fact": "Random fact 1"}},
{"pk": 2, "model": "didyouknow.fact", "fields": {"fact": "Random fact 2"}},
{"pk": 3, "model": "didyouknow.fact", "fields": {"fact": "Random fact 3"}},
{"pk": 4, "model": "didyouknow.fact", "fields": {"fact": "Random fact 4"}},
{"pk": 5, "model": "didyouknow.fact", "fields": {"fact": "Random fact 5"}}]
I want to write a piece of javascript that I can embed in my HTML that will randomly choose and print one of the “fact”s from the JSON URL.
Hopefully this helps:
Here’s an example that uses AJAX to call out to a (local) web service: