alternatives to eval for running remote code.
Posted
by
Raynos
on Stack Overflow
See other posts from Stack Overflow
or by Raynos
Published on 2011-01-05T14:21:02Z
Indexed on
2011/01/05
14:53 UTC
Read the original article
Hit count: 223
Are there any alternatives to using eval
to immediatly run remote & trusted javascript code.
function load(filePath) {
var o = $.ajax({
url: filePath,
dataType: 'html',
async: false
});
eval(o.responseText);
}
load("somePath");
// run a function that relies on the code from o.responseText being loaded
doSomethingWithCode();
I'm aware that synchronous loading of javascript is adviced againts. But if there is no choice are there any cross browser alternatives for the use of eval above.
[Edit]
To clarify in more detail the code being loaded is a self executing function. Which needs to execute before doSomethingWidthCode. It's also being loaded from the server on the same domain hence its trusted.
© Stack Overflow or respective owner