0
I want to recover a JSON code for HTML with jQuery. How can I do this? And how can I use CSS with JSON data?
Here is the JSON code.
{
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
}
},
"maths": {
"q1": {
"question": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"q2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
}
Where is this JSON? You need to receive it via AJAX?
– Woss
Welcome to Stackoverflow! What You Tried?
– Tomás Barcellos
@Andersoncarloswoss It would be nice without AJAX, because I’m having problems with the installation of Winlamp. The code folder is on the desktop, bearing in mind the problems with web server.
– Nithogg
@Tomásbarcellos I tried using js files to collect json information for html, but none were effective.
– Nithogg
So you want to read the disk file with Javascript? That’s not possible. You will need to get a web server serving the file and get it with an HTTP request.
– Woss
Take a look at AXIOS https://github.com/axios/axios and Vuejs https://br.vuejs.org/ If you want I can make an example and post as an answer.
– Tony
Which URL and method generates this
JSON
?– Tony
@Tony I’ve never seen about AXIOS, if I may I’d like an example.
– Nithogg
@Tony This JSON file was not built by me...
– Nithogg
@Joãovitor gives a read in the Axios documentation. An example of usage would be.
axios.get(http://suaurl/).
 then(response => { 
 //Aqui você pega a resposta e trata ela
})
.catch(err => {
 // Aqui trata algum erro na resposta
});
– Lucas Brogni
You can put here the URL that returns this JSON ?
– Tony
What people meant is that you have to have a source to get this result, whether it’s a string, a URL or a file. Anyway, to use Javascript you need to serve it because by security limitation JS does not allow you to read a file for it.
– Marco
I found an alternative here with some members, I apologize for my nonsense, it’s my first post officially in the stack [which has already become quite obvious].
– Nithogg