Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  11] [ 6]  / answers: 1 / hits: 45512  / 11 Years ago, tue, june 4, 2013, 12:00:00

I'm trying to populate a JSTree with JSON data that I'm obtaining from a service (which is called using ajax). However, I am getting a Neither data nor ajax settings supplied error in the jquery.jstree.js file. Because of this the JSTree just displays a loading gif.



AJAX code (editted to try setting json to local variable test, then return test)



function getJSONData() {
var test;
$
.ajax({
async : true,
type : GET,
url : /JavaTestService/rs/TestService/MyFirstTestService?languageCode=en_US&version=2,
dataType : json,

success : function(json) {
test = json;
},

error : function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
test = error;
}
});
return test;
}


JSTree code



var jsonData = getJSONData();
createJSTrees(jsonData);

function createJSTrees(jsonData) {
$(#supplierResults).jstree({
json_data : {
data : jsonData
},
plugins : [ themes, json_data, ui ]
});


After some debugging, I've found that jsonData is undefined when passed to the createJSTrees method. Am I retrieving that data correctly in the Ajax code?
Thanks in advance


More From » jquery

 Answers
14

I have not tested your approach before, where you supply the data parameter directly to the json_data plugin, so I won't be able to supply an answer to this scenario.



However, since you are using an AJAX call to get the data, can't you supply the AJAX call to JSTree and let it handle the call on its own? Here's how I've configured the AJAX call in my code:



        (...)
'json_data': {
'ajax': {
'url': myURL,
'type': 'GET',
'data': function(node) {
return {
'nodeId': node.attr ? node.attr(id) : ''
};
}
},
'progressive_render': true,
'progressive_unload': false
},
(...)

[#77821] Monday, June 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rossthomasn

Total Points: 122
Total Questions: 78
Total Answers: 105

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
rossthomasn questions
Wed, Mar 16, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Thu, Nov 26, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
;