Can I load state using stateLoadCallback using a variable?

Can I load state using stateLoadCallback using a variable?

pizzopizzo Posts: 7Questions: 2Answers: 0
edited March 2021 in Free community support

For testing purposes I have taken an old save state (from local storage) and saved it as a JSON string in a Java variable. This variable is saved to a Javascript object on page load. Is it possible to load state from either the Java or JS object using the stateLoadCallback?

Unfortunately I cannot submit a working demo of my code because of the Java portion. but the json string is saved/loaded successfully on the page:

var value = ${FormData.saveState};

Below is what I have for the stateLoadCallback fn.:

                stateLoadCallback: function(settings, callback) {
                    $.ajax( {
                        url: value,
                        "dataType": 'json',
                        "type": 'GET',
                        success: function(json) {
                            callback( json );
                    } );

It should be loading correctly, I would think, because console logging value shows the json object from the previous save state. But trying to load it gives me the following 400 error:

jquery-1.8.2.min.js:2 GET https://localhost:8000/project/[object%20Object] 400

This question has an accepted answers - jump to answer


  • kthorngrenkthorngren Posts: 14,649Questions: 25Answers: 3,478
    Answer ✓

    url: value,

    This needs to be a valid url not a JS object variable.

    This is according to the stateLoadCallback docs:

    If the data is loaded synchronously the return value should be the loaded state (or null if no data was loaded).

    Instead of trying to use an ajax request just use return value; to return a JS object variable.


  • pizzopizzo Posts: 7Questions: 2Answers: 0

    OMG...I must have read that page 100x idk how I missed that. I knew it was something stupid on my end.

    Many thanks @kthorngren , I greatly appreciate it!

Sign In or Register to comment.