开发者

How to execute contents of a script tag when HTML is returned from jQuery ajax call

I'm returning html with a script tag in it from a jquery ajax call. How can I execute the co开发者_JAVA技巧ntents of the script tag?


If the script had a function in it, you could call the function (i think). I think the browser may block this sort of activity to prevent cross site scripting attacks.


what exactly are you trying to achieve? this sounds like it could lead to bad places as it stands currently. (By bad places I mean XSS type exploits)


Use following code in the success callback of your ajax call.

$(result).filter("script").each(function () {
    eval(this.text);
});

This will execute all script code blocks in the result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜