Executing javascript script after ajax-loaded a page - doesn't work

后端 未结 4 1044
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 13:37

I\'m trying to get a page with AJAX, but when I get that page and it includes Javascript code - it doesn\'t execute it.

Why?

Simple code in my ajax page:

4条回答
  •  隐瞒了意图╮
    2020-12-11 14:11

    In case some other people stumble upon this old thread, there is one issue with the accepted answer by Deukalion, there is one issue that may have been overlooked: as written, the script only looks for the first script tag. If multiple script tags exist, all others are overlooked.

    A few minor tweaks would resolve the issue. Change one line from:

        var script = content.match("]*>[^<]*");
    

    To:

        var script = content.match(/]*>[^<]*<\/script>/g);
    

    And another from:

        script = script.toString().replace('
    
                                     
                  
提交回复
热议问题