Answer the question
In order to leave comments, you need to log in
How to sequentially read json file data and give it to the form?
There is a questionnaire interface that works without reloading the page and the data that is taken from the json file.
The option with one question is implemented, difficulties begin when there are many questions in a chain one after another.
How to make it so that to read data from a json file into an array and sequentially give it after clicking on the button to answer the next question?
I collect an array through
data.forEach(function(item) {});
, but if I put the answers function inside, then absolutely all the answers for different questions will simply be displayed on one page. How can the idea be realized?
Answer the question
In order to leave comments, you need to log in
There is a JSON.parse() function that will make an object out of it.
Respectively. At the first question, we turn to the 0th element of the object - our first question. We send the result to the server using ajax.
We remove this question, and instead show the question with index 1 in our object.
At the top of the page, you need to enter the answer questions variable.
Answers = 0
And after each answer to the question, increment it.
And, accordingly, to cling elements from an array with an index equal to this variable)
That's actually all, and there is no need for cycles in this situation if I understand the question correctly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question