I wrote an Ext JS 7.0 app with a grid that uses Ext Direct to connect to a SQL database based on the example by Sencha (https://docs.sencha.com/extjs/7.0.0/guides/backend_connectors/direct/mysql_php.html). This works fine.
The app has also some views with a few textfields. Their content is stored in the database, too, but in a different table, so I added the necessary functions to QueryDatabase.php and extended config.php. Now writing into the database works by simply calling the corresponding (php) function in the controller, e. g. QueryDatabase.updateSettings(JSONstring);.
I also want to initially populate the textfields with the data stored in the database and this is where I get into trouble.
If I call the proper read function and assign it to a variable, e. g. settingsJSON = QueryDatabase.getSettings();, settingsJSON stays undefined, although I can see in the browser that router.php returns the correct result (like "{\"Setting1\":\"a value\",\"Setting2\":\"another value\"}").
Since the request is asynchronous, I tried to use a callback function (according to https://docs.sencha.com/extjs/7.0.0/classic/Ext.direct.RemotingProvider.html#cfg-actions):
onSettingsRefreshClick: function() {
console.log('Hello world!');
QueryDatabase.getSettings(function(result, e, success, options) {
console.log('Hello again!');
var t, action, method;
t = e.getTransaction();
action = t.action;
method = t.method;
if (e.status) {
console.log(Ext.encode(result));
}
})
}
But this isn't working either. router.php still delivers the correct result, but it isn't shown in the console. Obviously the whole callback function isn't executed as 'Hello again!' also doesnt't appear in the console ('Hello world!' does). So how do I assign the JSON string returned by router.php to a variable?