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

后端 未结 4 1054
爱一瞬间的悲伤
爱一瞬间的悲伤 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:28

    Use this function:

    function parseScript(_source) {
        var source = _source;
        var scripts = new Array();
    
        // Strip out tags
        while(source.indexOf(" -1 || source.indexOf(" -1) {
            var s = source.indexOf("", s);
            var e = source.indexOf("", e);
    
            // Add to scripts array
            scripts.push(source.substring(s_e+1, e));
            // Strip from source
            source = source.substring(0, s) + source.substring(e_e+1);
        }
    
        // Loop through every script collected and eval it
        for(var i=0; i

    then do parseScript(xmlhttp.responseText); when you're replacing/adding content.

提交回复
热议问题