test1.html file:
You need not "load" it into your DOM. For script tags, you could just do..
eval("<script>alert('Hi!');</script>");
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
}
});
you need to do something like this so that it loads script element , so my advise is when you get response replace script
string with scri" + "pt
var code = "<script>alert('Hi!');</scr"+"ipt>";
$('body').append($(code)[0]);