Question T4841
Visible to All Users

Pause screen repaint until current page is set during load

created 4 years ago (modified 4 years ago)

Hi,

In my loadState function, I'm setting the current page to where the user last let off. This works fine, except that the first survey page is displayed initially, than after a small but perceptible lag, the desired page is painted.

Is there any way to pause the screen paint, until the desired page is loaded?

Here's my loadState function for your reference:

JavaScript
function loadState(survey, isInitialLoad = false) { //Here should be the code to load the data from your database var xhr = new XMLHttpRequest(); xhr.open("GET", "/Survey/Survey/SurveyData", true); xhr.responseType = "json"; // - Send Anti-Forgery Token (otherwise a BAD REQUEST ERROR (400) will be returned) xhr.setRequestHeader("XSRF-TOKEN", $('input:hidden[name="__RequestVerificationToken"]').val()); xhr.send(); xhr.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { var surveyResponse = this.response; survey.clear(); // Clear the survey state survey.data = surveyResponse.data; // Load data if (isInitialLoad) { survey.currentPageNo = surveyResponse.currentPageNo; // Set survey page to where user left off } } else { //error or not ready } } }

Thanks,
Alan

Answers approved by surveyjs Support

created 4 years ago

Hello Alan,
The easiest solution is to keep your survey div hidden until you are not finish with loading and then show it. You just need to set your div style display attribute.
You can show a div with your text or image or gif with loading cycle, while you are loading the survey.

Thank you,
Andrew
SurveyJS Team

    Other Answers

    created 4 years ago

    Thanks Andrew, that was really helpful.

    I set the 'display:none' property on the survey div and and added the following code to the bottom of my survey js script. It worked great.

    JavaScript
    $(document).ready(function () { document.getElementById('surveyElement').style.display = "block"; })
      Comments (1)

        Fine, feel free to contact us in case of any further questions