After obtaining the remote page content using Ajax, I found that the script block in it was not executed. I felt that the code was transferred to the current page, but it was not convenient, secondly, you can search for the content of all the script blocks, reload the JS file, and re-execute the code, which is less efficient, but more convenient.
We wrote a callback to solve this problem:
VaR processrequest = function (_ instance)
{
Document. getelementbyid ('tdiv '). innerhtml + = _ instance. responsetext;
VaR _ c = Document. getelementsbytagname ("script ");
VaR _ first = NULL;
For (VAR I = 0; I <_ c. length; I ++)
{
If (_ c [I]. SRC)
{
VaR _ S = Document. createelement ("script ");
_ S. type = "text/JavaScript ";
_ S. src = _ c [I]. SRC;
_ C [0]. insertadjacentelement ("beforebegin", _ s );
_ C [I]. parentnode. removechild (_ c [I]);
}
Else if (_ c [I]. Text)
{
Window.exe cscript (_ c [I]. Text );
}
}
}
When the page content is obtained, the script block is already in the DOM tree and is executed as text.