I have a unique scenario where I am handling a JavaScript code that is generated server-side and passed to the client as a string via a REST request. My goal is to execute this retrieved code successfully. Any assistance on how to approach this would be highly appreciated.
On the server-side, we have the JavaScript code stored as a string.
(function() {
function createVisual(selector) {
$(selector).visualize({
chart: {
type: 'bar',
},
xAxis: {
crosshair: true,
type: "category"
},
yAxis: {
min: 0,
title: {
text: null
}
},
dataSeries: [{
dataset: data
}],
});
}
function displayGraphics() {
createVisual('#visual');
}
return {
render: displayGraphics
}
}())
On the client side (using AngularJS)
.controller('GraphController', ['$scope', 'graphs', function ($scope, graphs) {
var script = graphs.info; // contains the JavaScript code obtained from a REST request
eval(script);
script.render();
}])
When attempting to execute the script on the client-side, an error message of "script.render is not a function" is displayed in Chrome.
If you have any insights or advice on resolving this issue, please feel free to share them.
Your help is greatly appreciated.