The documentation for jQuery can read:
When passing in complex HTML, some browsers may not generate a DOM that exactly replicates the HTML source provided. As mentioned, jQuery uses the browser's .innerHTML
property to parse the passed HTML and insert it into the current document. During this process, add browsers filter out certain elements such as <html>
, <title>
, or <head>
elements. As a result, the inserted elements may not be representative of the original string passed.
Basically this means that whole pages can not be imported via AJAX, nor via jQuery(stringDePáginaInteira)
, and that html elements of that string such as html
, head
and title
are removed.
Then $(data).find("html")
will be empty.
The correct way, and the reason that ajax is useful, is to ask via ajax only the minimum data needed. Otherwise it's better to reload the page or an iFrame with that content. And if you need parameters via GET.
That said, it is possible to import HTML via ajax, but in this case it is better to use more secure html tags, basically anything that can be inside body
.
Example: link
(and note that the first element passed is not even body
)