Chartjs-Pug โ€“ Access data from server in pug script(type='text/javascript')

1๐Ÿ‘

I think you are mixing different contexts. The line that gives you an error is executed in the browser, and in that context, there is no variable named result.

Since you have a endpoint /serverdata on your server in place, all you need to load and parse the data from that URL. Details depend on what kinds of JavaScript libraries you are using, but with jQuery getJSON:

$.getJSON("/serverdata", function(data) {
    /* Update your chart by using 'data' */
});

Leave a comment