路过的JavaScript code以JSONJavaScript、code、JSON

2023-09-10 20:15:05 作者:颓废人物

我想提出一个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,和而不是做一个电话,让您的客户端脚本插入&LT;脚本&GT; 及其的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 its src 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.

 
精彩推荐
图片推荐