Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jstree 3.0.2 dynamic tree always loading data from cache instead of making a fresh call to server

I have a jstree. on load of the page the jstree populates fine from the server as it make a fresh call to server, but after that whenever I refresh the page it will always take the data from cache and not make a call to server , thereby always taking the old data to populate. I am using jstree 3.0.2 version. following is the code which generated the jstree on load of the page .

$('#tree').jstree({
'core': {
data:{
'url':'getjstree'   // this is the url which will get the json data from the server
}
}});

how do we solve this to get fresh data on each call, one solution which I earlier thought of using is the javascript code to hard refresh by calling

location.reload(true);

but that did refresh the json data but went into recursive call and thereby hanging the page. Please help how can we solve this issue.

like image 488
Chetan Avatar asked Mar 18 '23 17:03

Chetan


1 Answers

JSTree plugin saves tree state in browser's localStorage with key "jstree". So before calling jstree you should erase that key from localStorage, like this:

//Removes jstree cached state from localStorage
localStorage.removeItem('jstree');

$('#tree').jstree({
    'core': {
        data:{
            'url':'getjstree'
        }
    }
});
like image 56
André Bonna Avatar answered Mar 22 '23 23:03

André Bonna