when you load an html document using AJAX what does it do with the nodes inside the HEAD tag: (script, link, style, meta, title)
It depends on how you download. ajax() (as with the XMLHttpRequest on which it is based) itself just gives you a string. How do you get this in a document?
If you write this line in the innerHTML element, the scripts inside it will not be executed. This is not standardized anywhere, but all currently popular browsers behave this way.
However, if you then insert this element into the document (whether it is already inside the document with or without it), it will be executed in many browsers when you do this for the first time. In IE, the script will execute when you directly insert the script element into any element, whether in the document or not.
This is all very inconsistent and inconvenient, so you should avoid the AJAX <script> loading elements in the document. In any case, there is not always a good reason; itβs better to save the static script code and use JSON (or eval only if absolutely necessary) to pass script data to them.
Function
jQuery load tries to compensate for browser differences when loading AJAX content into a document. It cannot catch all the circumstances surrounding <script> (there are some really strange ones). You should not rely on this, in general. You can get away with the response to the HTML page, but then only load certain elements (s) without <script> in, because this is just a-to-innerHTML write step. But then again, you really don't want to rely on it. It is much better if the server returns an HTML or JSON fragment that your scripts can use directly.
As for style sheets and style links, inserting them into the body generally works, although this probably should not be done with HTML expressions. meta and title will not do anything, too late for them to effect. Just parsing them with innerHTML won't do anything, but avoid it if you can anyway.
bobince Feb 05 2018-10-02T00 : 00Z
source share