Executing [removed] injected by innerHTML after AJAX call

前端 未结 11 1603
误落风尘
误落风尘 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:28

    Here is a function you can use to parse AJAX responses, especially if you use minifiedjs and want it to execute the returned Javascript or just want to parse the scripts without adding them to the DOM, it handles exception errors as well. I used this code in php4sack library and it is useful outside of the library.

    function parseScript(_source) {
        var source = _source;
        var scripts = new Array();
    
        // Strip out tags
        while(source.toLowerCase().indexOf(" -1 || source.toLowerCase().indexOf(" -1) {
            var s = source.toLowerCase().indexOf("", s);
            var e = source.toLowerCase().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

提交回复
热议问题