After making an AJAX call, I receive a random string (constructed dynamically on the server) that contains JavaScript code like:
Plugins.add('test', function()
{
return
{
html: '<div>test</div>',//EDITED
width: 200
}
});//EDITED
I want to be able to execute this code on the client side. I attempted to use the eval
function in this way:
eval("(" + str + ")");
However, I encountered an error. After removing all instances of "\r\n" and eliminating the last ";" (semicolon), the eval
function was successful. But, if I include any comments in the code above, the eval
function fails.
Is there a way for me to successfully run the code from the string?