Ajax post and gantt.load problem

Hello!

Have some code:

$.ajax({
url: '/data.php',
method: "POST",
data: { 
    t: 'macroregion' 
},
error: function () { console.log(error); },
complete: function (data) {        
	gantt.load(JSON.parse(data.responseText));
}
});

data.php response:

But get error:

bluebird.js:1564 Unhandled rejection TypeError: i.indexOf is not a function
    at http://localhost/codebase/dhtmlxgantt.js?v=6.0.3:10:397310
    at D.i._execute (http://localhost/codebase/dhtmlxgantt.js?v=6.0.3:10:319433)
    at D._resolveFromExecutor (http://localhost/codebase/dhtmlxgantt.js?v=6.0.3:10:349820)
    at new D (http://localhost/codebase/dhtmlxgantt.js?v=6.0.3:10:342993)
    at Object._call (http://localhost/codebase/dhtmlxgantt.js?v=6.0.3:10:396717)
    at Object.query (http://localhost/codebase/dhtmlxgantt.js?v=6.0.3:10:396036)
    at Object.get (http://localhost/codebase/dhtmlxgantt.js?v=6.0.3:10:396167)
    at Object.t.load (http://localhost/codebase/dhtmlxgantt.js?v=6.0.3:10:144057)
    at Object.complete (<anonymous>:11:9)
    at u (http://localhost/js/jquery-3.3.1.min.js:2:27457)
    at Object.fireWith (http://localhost/js/jquery-3.3.1.min.js:2:28202)
    at k (http://localhost/js/jquery-3.3.1.min.js:2:77779)
    at XMLHttpRequest.<anonymous> (http://localhost/js/jquery-3.3.1.min.js:2:79907)

What’s wrong in my code?

Hello, @DiWorm !
Your mistake in this line. You need to use gantt.parse() instead of gantt.load()
pasted image

gantt.load() takes URL as an argument and it loads data to the gantt from an external data source via AJAX request
https://docs.dhtmlx.com/gantt/api__gantt_load.html

gantt.parse() takes either JSON string or data object as an argument, parses it and adds to gantt
https://docs.dhtmlx.com/gantt/api__gantt_parse.html

Can you please try the following code, it should work correctly
$.ajax({ url: '../common/data.json', method: "POST", data: { t: 'macroregion' }, error: function (error) { console.log(error); }, complete: function (data) { gantt.parse(data.responseText); } });

1 Like

gantt.parse(JSON.parse(data.responseText); ‘json’);

work for me! thx!