评估responseText/responseXML性能
有谁知道使用 eval()
和 responseText
(使用 JSON)是否比仅使用 responseXML
更快或更慢?
我认为避免使用 eval()
并使用 responseXML
会更快,尽管事实上您必须编写很长的代码才能实际获取 XML 的值。
谢谢。
Does anyone readily know if using eval()
and responseText
(using JSON) is faster or slower than just using responseXML
?
I would imagine avoiding the eval()
and using responseXML
instead would be faster, despite the fact that you gotta write really long code to actually get the values of the XML.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,JSON 数据大多数时候都比 XML 小。
最好不要使用
eval()
,因为这是一个众所周知的安全漏洞。但我听说过正则表达式可以检查 JSON 合规性。我不喜欢 XML,所以我避免使用它,但我认为 responseXML 将构建一个 DOM 模型,该模型比
responseText
创建的本机 javascript 对象重得多,我想最大限度地减少带宽 JSON 是可能是比 XML 更好的选择。
Actually JSON data are most of the time smaller than XML.
It is better to not use
eval()
because it is a well known security leak. But I've heard of regular expression which can check the JSON compliance.I do not like XML so I avoid it, but I suppose that the responseXML will build a DOM model which is much more heavier than the native javascript objects created by
responseText
I you want to minimize the bandwidth JSON is probably a better choice than XML.
使用 JSON 并使用解析器而不是 eval。这是一个 - https://github.com/douglascrockford/JSON-js
Use JSON and use a parser instead of eval. Here's one - https://github.com/douglascrockford/JSON-js