来自 ajax 的字符串作为 jquery 执行

发布于 2024-12-26 12:36:06 字数 227 浏览 2 评论 0原文

我进行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谜泪 2025-01-02 12:36:06

您可以使用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.

半衾梦 2025-01-02 12:36:06

javascript 是一个脚本。也许你可以将标志响应为 (1,2) 而不是脚本字符串。我认为 。

javascript is a script. maybe u can response a flag as (1,2) not a script string. i think .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文