Where are scripts loaded after an ajax call?

后端 未结 5 497
日久生厌
日久生厌 2020-12-11 05:44

suppose you have a simple web page that dynamically loads content that looks like this:

- main.html -




        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 06:22

    you can use $.ajax to get the html, strip out the script tags yourself, append the content, and then append the script tag to the location in the dom where you want it so that it executes the way you want it to.

    $.ajax({...}).done(function(html){
      var htmlToAppend = html;
    
      // replace all script tags with divs
      htmlToAppend.replace(/
    
                                     
                  
提交回复
热议问题