Is there a limit to javascript’s eval, like in lenght?
I’m trying to build an app where you can store JS code in the DB, which you can later load and eval in order to execute it, but i’m reaching a limit.
First of all, the code has to all be in one line. Any multiline statements are not executed.
Next, i’m reaching a limit in length (i guess). If i execute the code manually, it works, but put that same code in the db, load it via ajax, and try to execute it, and it fails.
Any ideas why?
You could create a javascript function that creates a script-tag dynamically (
createElement('script')and append it to the head- or bodytag) and point the source to your app. The src can contain parameters, used like a get request, like for example:src="jsapp.aspx?script=myscript&includefunction=loadfn"No eval needed. You can even define an onload handler for your new script tag. Plenty of documentation on the net for that.You wouldn’t even have to use XHR (AKA Ajax) for that.