how to load the Jquery response(HTML page with script tags) into the DOM

后端 未结 2 626
死守一世寂寞
死守一世寂寞 2021-01-26 06:07

test1.html file:






        
2条回答
  •  天命终不由人
    2021-01-26 06:55

    You need not "load" it into your DOM. For script tags, you could just do..

    eval("");
    

    UPDATE :

    If you result contains both HTML and SCRIPT nodes, do the following..

    $.each(nodes, function(i, node) { //result might contain muliple HTML/Script nodes
    
       if (node.tagName == "SCRIPT") {
           eval(node.innerHTML); 
           //Appending to DOM also executes the script. So we do eval() instead, which does the equivalent.
       } else {
           $(node).appendTo($('#returnData')); //And append your HTML nodes to the desired target div
       }
    
    });
    

提交回复
热议问题