In the documentation of jQuery can be 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, some browsers filter out Certain Elements such as <html>
, <title>
, or <head>
Elements. As a result, the Elements inserted may not be Representative of the original string passed.
Basically this means that whole pages cannot be imported via AJAX, nor via jQuery(stringDePáginaInteira)
, and what html elements of that string as html
, head
and title
are removed.
Hence $(data).find("html")
will be empty.
The correct way, and the reason that ajax is useful, is to ask via ajax only the minimum necessary data. Otherwise it is better to reload the page or an iframe with this content. And if you need parameters via GET.
That being said, it is possible to import HTML via ajax, but in this case it is better to use more secure html tags, in the background everything that can be inside body
.
(and notice that the first past element is not even the body
)
what you send from PHP to ajax?
– Sergio
an entire HTML page, the return exists, I saw in the reply and in fact it returns the page in the request.
– Ale