Javascript eval 导致 IIS 上的语法错误
我正在尝试在服务器端使用 javascript 代码将 JSON 输入解析为对象。因为经典 asp 中没有对 JSON 反序列化的本机支持,所以我尝试使用 Douglas Crockford 的 javascript 库 https://github.com/douglascrockford/JSON-js/blob/master/json2.js 作为服务器端代码包含在内。
我已经使用了此解决方案在 IIS Express 上没有问题,但是当我将代码移到常规 IIS 上时,我遇到了此错误:
Microsoft JScript compilation error '800a03ea'
Syntax error
而这一行是罪魁祸首 j = eval('(' + text + ')');
。
所以我开始用类似的东西来愚弄它:
text = '(' + text + ')';
j = eval(text);
但是 line with eval 总是会导致错误。在没有成功之后,我尝试简化代码以消除任何可能的干扰,并得到这个仍然会导致错误的简单代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>test</title>
<script type="text/jscript" language="jscript" runat="server">
function Test(text) {
eval('(' + text + ')');
}
</script>
</head>
<body>
<p><% Test("Test") %></p>
</body>
</html>
我的问题是,有人知道什么会导致常规 IIS 不喜欢这种 eval 的使用吗?
I am trying to use javascript code in server side to parse JSON input into object. Beause there is no native support for JSON deserialization in classic asp, I have tried to use Douglas Crockford's javascript library https://github.com/douglascrockford/JSON-js/blob/master/json2.js included as server side code.
I have used this solution on IIS Express without problem, but when I moved my code on regular IIS I have experienced this error:
Microsoft JScript compilation error '800a03ea'
Syntax error
and this line was the culprit j = eval('(' + text + ')');
.
So I started to fool it with something like:
text = '(' + text + ')';
j = eval(text);
but line with eval always caused error. After no success I have tried to simplify the code to eliminate any possible interference and come to this simple code which still causes error:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>test</title>
<script type="text/jscript" language="jscript" runat="server">
function Test(text) {
eval('(' + text + ')');
}
</script>
</head>
<body>
<p><% Test("Test") %></p>
</body>
</html>
My question is, does anybody have a clue what can cause regular IIS to dislike this use of eval?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知道
text
的值,但您尝试计算的最终字符串格式无效。也许是因为你添加了括号。不管怎样,为了让你的测试工作,首先将函数更改为:
然后传递给它一些可以评估的东西:
对我来说工作得很好。
Don't know the value of
text
but the final string you try to evaluate is not in valid format. Maybe because of the brackets you add.Anyhow, to make your test work first change the function to:
Then pass to it something that can be evaluated:
Worked fine for me.