Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON read fail #2800

Open
kerverosmx opened this issue Jan 24, 2025 · 0 comments
Open

JSON read fail #2800

kerverosmx opened this issue Jan 24, 2025 · 0 comments

Comments

@kerverosmx
Copy link

Hi, I'm using JSON format, but the tree never create in correct form, this is the result of my AJAX call:

[{"text":"Menú", "state":{ "opened":true },"children": [{"text":"Configuración", "state":{ "opened":true }, "children":[{"text":"Usuarios"},{"text":"Grupos"},{"text":"Opciones de menú"}]}]}]

This is the configuration of the tree:
$('#container').jstree({
"core" : {
"data" : {
"url" : "/menust",
"dataType" : "json" // needed only if you do not supply JSON headers
},
"animation" : 1,
"check_callback" : true,
"html_titles" : true,
"load_open" : true,
"themes" : {
"variant" : "large"
}
},
"plugins" : ["changed"]
});

this is my web page:

<title>Menú</title> <script type="text/javascript" src="../static/js/jquery-3.7.1.js"></script> <script type="text/javascript" src="../static/js/bootstrap.min.js"></script> <script type="text/javascript" src="../static/js/jstree.min.js"></script> <script type="text/javascript" src="../static/js/font.all.js"></script> <script> document.onreadystatechange = function(){ if(document.readyState == "loaded" || document.readyState == "complete"){ const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); var IDG = urlParams.get('IDG'); var data = { idg: IDG }; $.ajax({ url: '/menust', type: 'POST', contentType: 'application/json', data: JSON.stringify(data), success: function (dat) { createJSTrees(dat); }, error: function (xhr) { console.log('error') console.log(xhr) } }); } }
        function createJSTrees(jsonData) {
            $('#container').jstree({
               "core" : {
                   "data" : {
                       "url" : "/menust",
                       "dataType" : "json" // needed only if you do not supply JSON headers
                   },
                   "animation" : 1,
                   "check_callback" : true,
                   "html_titles" : true,
                   "load_open" : true,
                   "themes" : {
                       "variant" : "large"
                   }
               },
               "plugins" : ["changed"]
           });
        }
</head>
<body>
    <div class="container mt-12">
        <div id="container">
        </div>
    </div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant