Skip to content

Show loader while async function fetches data #3234

Answered by Shaobin-Jiang
talkoren asked this question in Q&A
Discussion options

You must be logged in to vote

The example uses a timeout and a line of text instead of a request to the server and the loader gif, but things should work the same way.

let jsPsych = initJsPsych();

let timeline = [];

let trial = {
    type: jsPsychCallFunction,
    func: function (done) {
        setTimeout(function () {
            jsPsych.getDisplayElement().innerHTML = '';
            done();
        }, 5000);
    },
    async: true,
    on_start: function () {
        jsPsych.getDisplayElement().innerHTML = 'Please wait for 5 seconds...';
    },
};

jsPsych.run([trial]);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@talkoren
Comment options

Answer selected by talkoren
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants