Hi All,

Trying to use google chart objects dynamically via Ajax. When I call the back end normally using the Visualisation module I get the appropriate page div and settings JSON which is then used to build the chart.

But when I use:

$response = new AjaxResponse();
$response->addCommand(new ReplaceCommand('#graph', $container, $settings));
return $response

in a callback function the div is replaced with a new one but the pages settings JSON in:
<script type="application/json" data-drupal-selector="drupal-settings-json">...</script>

does not change.

Ive even used:
$response->addCommand(new SettingsCommand($settings, TRUE), TRUE);

to place it directly and preferentially first to no avail.

Am I missing something?

If the replace command fires should not also the script be replaced or appended?

Comments

dj12djdjs’s picture

I'm also trying to update drupal settings via an Ajax Request, however I'm not having much luck ether. Does anyone know where some examples of implementation are? Here is what I've tried.

$response = new AjaxResponse();

$data = [1, 2, 3, 4, 5];

$response->addCommand(new SettingsCommand(['myData' => $data]));
return $response;

The myData array will remain as it did before the Ajax executed.