jQuery: Evaluate script in ajax response

前端 未结 4 1087
南笙
南笙 2020-11-30 15:13

XML responses from my webapp have both HTML to add to the page AND some have a script to run.

I\'m trying to send back XML from my webapp like:



        
4条回答
  •  旧巷少年郎
    2020-11-30 15:53

    You'd rather send JSON, it's way easier to interpret. Example:

    // Suppose your response is a string:
    // { html: "

    add me to the page

    , script:"alert('execute me');" } var obj = eval( "(" + response + ")" ) ; eval( obj.script ) ;

提交回复
热议问题