对于Ajax响应是Eval Evil吗? [英] Is Eval Evil for Ajax Responses

查看:32
本文介绍了对于Ajax响应是Eval Evil吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:


我在这个论坛上看过很多关于eval()及其邪恶的贴子。

但是,我们的一位开发人员正在使用它以下面的方式,

这似乎很好用。


Page向ASP.Net Web服务发出Ajax请求。 Web服务执行一些

数据查找并构建一个Javascript数组的字符串表示

然后返回给客户端。在ajax回调中,在返回的字符串上调用

eval,即时填充数据

结构。


另一种方式要做到这一点,就是回传xml并在回调中走xml dom

,随时填充一个数组。


无论哪种方式你都要在服务器上做大致相同的工作量

(没有xml可能会略微减少)。


我并不担心eval的汇编' '字符串。我们的测试

闪电般快速。这种情况下最大的危险是x-browser

问题?


谢谢,


拉里

解决方案

2005年11月16日07:51:59 -0800,Larry < LP **** @ gmail.com>写道:

我并不担心eval'字符串的编译。我们的测试快速闪电了。在这种情况下,x-browser
问题是最大的危险吗?




不,这是使用eval的一个很好的理由。


我亲自使用


新功能(返回+ str)();


但无论如何这是一种明智的方法,比

XML文档更明智。


另一种选择是iframe和常规脚本元素而不是

比xmlhttp方法。


Jim,


JRS:文章< 43 **** ************@news.individual.net> ;,日期为星期三,16

2005年11月15:54:51,见于新闻:comp.lang.javascript, Jim Ley

< ji*@jibbering.com>发表:

2005年11月16日07:51:59 -0800,Larry < LP **** @ gmail.com>写道:

我并不担心eval'字符串的编译。我们的测试快速闪电了。在这种情况下x浏览器的最大危险是什么?



不,这是使用eval的一个很好的理由。

我个人使用

新功能(返回+ str)();

但无论哪种方式,它都是明智的做法,比
更明智XML文档。




是否值得添加到新闻组常见问题解答部分?


据推测,它可能会以同样的方式被误用作为本机eval。


它确实有一个缺点,即对于

代码的读者来说不那么明显,而且更长;怎么样

函数EVAL(str){return new Function(" return" + str)()}

到OP:FAQ 4.40表示你的用法是声音。


-

?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 IE 4?

< URL:http://www.jibbering.com/faq/> JL / RC:新闻常见问题:comp.lang.javascript

< URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr数学,日期,来源。

< URL:http://www.merlyn.demon.co.uk/> TP / BP / Delphi / jscr /& c,FAQ项目,链接。


Larry写道:

你好:

我在这个论坛上看过很多关于eval()及其版本的帖子。
然而,我们的一个开发人员正在以下面的方式使用它,
这似乎很好用了它。

页面向ASP.Net Web服务发出Ajax请求。 Web服务执行一些数据查找并构建Javascript数组的字符串表示
然后返回给客户端。在ajax回调中,在返回的字符串上调用
eval,并且即时填充数据结构。

另一种方法是传回xml并走在回调中使用xml dom
,随时填充数组。

无论哪种方式,你都必须在服务器上做大致相同的工作量
(也许稍微少一些就没有了xml)。

我并不担心eval'字符串的编译。我们的测试快速闪电了。在这种情况下x-browser
问题是最大的危险吗?




听起来很像JSON:


< URL:http://www.crockford.com/JSON/index.html>


-

Rob


Hi there:

I have seen numerous postings about eval() and its evils on this forum.
However, one of our developers is using it in the following way,
which seems like a great use of it.

Page makes Ajax request to ASP.Net web service. Web service does some
data lookup and builds a string representation of a Javascript array
which is then returned to the client. In the ajax callback, call to
eval on the returned string and voila, instant populated data
structure.

Another way to do this would be to pass back xml and walk the xml dom
in the callback, populating an array as you go.

Either way you have to do roughly the same amount of work on the server
(perhaps slightly less with no xml).

I am not worried about the compilation of the eval''d string. Our tests
have been lightning fast. Is the biggest danger in this case x-browser
issues?

Thanks,

Larry

解决方案

On 16 Nov 2005 07:51:59 -0800, "Larry" <lp****@gmail.com> wrote:

I am not worried about the compilation of the eval''d string. Our tests
have been lightning fast. Is the biggest danger in this case x-browser
issues?



No, this is a perfectly fine reason to use eval.

personally I use

new Function("return "+str)();

but either way it''s a sensible approach, much more sensible than an
XML document.

One other alternative is iframe''s and regular script elements rather
than xmlhttp methods.

Jim,


JRS: In article <43****************@news.individual.net>, dated Wed, 16
Nov 2005 15:54:51, seen in news:comp.lang.javascript, Jim Ley
<ji*@jibbering.com> posted :

On 16 Nov 2005 07:51:59 -0800, "Larry" <lp****@gmail.com> wrote:

I am not worried about the compilation of the eval''d string. Our tests
have been lightning fast. Is the biggest danger in this case x-browser
issues?



No, this is a perfectly fine reason to use eval.

personally I use

new Function("return "+str)();

but either way it''s a sensible approach, much more sensible than an
XML document.



Is yours worth adding to the newsgroup FAQ section?

Presumably it can be misused in the same way as native eval.

It does have the disadvantages of being less obvious to a reader of the
code, and longer; how about
function EVAL(str) { return new Function("return "+str)() }
To the OP : FAQ 4.40 indicates your usage as being sound.

--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ?
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


Larry wrote:

Hi there:

I have seen numerous postings about eval() and its evils on this forum.
However, one of our developers is using it in the following way,
which seems like a great use of it.

Page makes Ajax request to ASP.Net web service. Web service does some
data lookup and builds a string representation of a Javascript array
which is then returned to the client. In the ajax callback, call to
eval on the returned string and voila, instant populated data
structure.

Another way to do this would be to pass back xml and walk the xml dom
in the callback, populating an array as you go.

Either way you have to do roughly the same amount of work on the server
(perhaps slightly less with no xml).

I am not worried about the compilation of the eval''d string. Our tests
have been lightning fast. Is the biggest danger in this case x-browser
issues?



Sounds a lot like JSON:

<URL:http://www.crockford.com/JSON/index.html>

--
Rob


这篇关于对于Ajax响应是Eval Evil吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆