来自 ajax 的字符串作为 jquery 执行
我进行 ajax 调用,并收到从服务器返回的字符串(这也可能是另一个字符串和链):
thisitem.parent().parent().hide()
现在我想执行该 jquery 链。我相信 eval()
是答案,但我知道这很危险?
那么还有什么选择呢?或者 eval()
对于这个目的来说并不危险吗?
I make an ajax call and I receive a string back from the server (this could also be another string and chain):
thisitem.parent().parent().hide()
Now I want to excecute that jquery chain. I believe eval()
is the answer, but I understand that that's dangerous?
So what's the alternative? Or is eval()
not dangerous for this purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用http://code.google.com/p/jquery-json/ 或 https://github.com/douglascrockford/JSON-js 库将 json 转换为 javascript对象。实际上浏览器对此有本机支持,但不是全部。因此,目前建议使用其他工具。
You can use http://code.google.com/p/jquery-json/ or https://github.com/douglascrockford/JSON-js library to convert json to javascript objects. Actually browsers have native support for this but not all of them. So using an another tool is recomended for now.
javascript 是一个脚本。也许你可以将标志响应为 (1,2) 而不是脚本字符串。我认为 。
javascript is a script. maybe u can response a flag as (1,2) not a script string. i think .
使用 jQuery.getScript()
http://api.jquery.com/jQuery.getScript/
Use jQuery.getScript()
http://api.jquery.com/jQuery.getScript/