You can simplify your code by using the
AppSettingsExpressionBuilder class[
^]:
var key1 = '<%$ AppSettings:AESKey %>';
Since you're no longer using the
<%= ... %>
construct, this should also resolve the error.
NB: You need to be absolutely sure that the appSettings value will not contain a single-quote character (
'); otherwise, your Javascript will not be valid.