Working method to allow JS to run in AJAX .responseText with insertAdjacentHTML (Plain JS)

后端 未结 2 1029
滥情空心
滥情空心 2021-01-28 18:46

I read and I tried many methods from posts and from Google on how to get the AJAX .responseText to allow JS to run and none of the methods either don\'t work or gav

2条回答
  •  甜味超标
    2021-01-28 19:43

    After you have insertAdjacentHTML-ed, how about eval-ing the scripts manually.

    document.querySelectorAll('#ajax script').forEach(script => {
        script.remove()
        eval(script.innerHTML)
    })
    

提交回复
热议问题