How can I make an AJAX or API call in an addon

How can I make an AJAX or API call in an addon, i.e. via javascript (cockpit frontend), e.g. if I have a chart and generate the data in the backend and prepare it as JSON?

Hi @Rolf

You want to get data from Cockpit in your frontend, right?
If that’s the case, please refer to the docs.

Let me know if this helped.

not in my frontend. in the fronted of cockpit.
the ajax-call must call on a part of the code from addon. and the fontend part of same plugin must call over javascript on this same area of plugin.

@Rolf Have a look at the core modules and App.request().

In short:

$app->bind('/mydata', function() {
    return ['key' => 'value'];
});
App.request('/mydata').then(function(data) {
    console.log(data);
});

References: