路过的JavaScript code以JSON [英] Passing javascript code in JSON
本文介绍了路过的JavaScript code以JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提出一个AJAX调用使用jQuery到需要恢复的javascript code嵌在JSON结果jQuery的code执行PHP脚本。我该如何去通过JavaScript的code以JSON?
I am making an AJAX call with jQuery to a PHP script that needs to return javascript code embedded in a JSON result for the jQuery code to execute. How do I go about passing javascript code in JSON?
推荐答案
有两种方式:
- 您就必须把它作为一个字符串,并使用
的eval()
在客户端上。 - 您可以使用JSONP,和而不是做一个电话,让您的客户端脚本插入
<脚本>
及其的src
指向服务器端code,返回新的脚本。
- You'll have to pass it as a string and use
eval()
on the client side. - You can use JSONP, and instead of doing a call, have your client side script insert a
<script>
with itssrc
pointing to the server-side code that returns the new script.
在这两种情况下,一定要保护好它 - 如果用户能以某种方式插入自己的code到你的回应,他们可以做一些损害
In either case, make sure you secure it well - if the user can somehow insert their own code into your response, they could do some damage.
这篇关于路过的JavaScript code以JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文