Through AJAX I receive random string (built at RUNTIME on the server) that contain some JavaScript code like:
Plugins.add('test', function()
{
return
{
html: '<div>test</div>',//EDITED
width: 200
}
});//EDITED
In the client I want to be able to execute this code. I tried using eval function like this
eval("(" + str + ")");
but I get error. I removed all "\r\n" and removed the last ";"(semicolon) and after that eval function succeeded. But, If I add some comment to the code above, eval fails.
How I can run the code from the string?