how to execute ajax output script

后端 未结 5 452
故里飘歌
故里飘歌 2021-01-20 11:02

I\'m getting an ajax output success data.

Where the data contains some html text and a script.

But the script is not executing, how can I execute the script.

5条回答
  •  感动是毒
    2021-01-20 11:45

    If you are retrieving the JSON formatted result from AJAX call, you can just use eval to execute the javascript.

    Assume, if the result json is formed like this

       var res =  '{"Data": "",
                  "script": "alert(something)"}';
    
       var out = eval("(" + res + ")");
       var data = out.data;
       eval(out.script);
    

提交回复
热议问题