Executing [removed] injected by innerHTML after AJAX call

前端 未结 11 1586
误落风尘
误落风尘 2020-11-22 05:02

There\'s a div called \"Content\":

It should be filled with data from a PHP file, by AJAX, including

11条回答
  •  长情又很酷
    2020-11-22 05:32

    JavaScript inserted as DOM text will not execute. However, you can use the dynamic script pattern to accomplish your goal. The basic idea is to move the script that you want to execute into an external file and create a script tag when you get your Ajax response. You then set the src attribute of your script tag and voila, it loads and executes the external script.

    This other StackOverflow post may also be helpful to you: Can scripts be inserted with innerHTML?.

提交回复
热议问题