Chris Walsh
Chris Walsh

Reputation: 3523

Request.HTML - only returning <body> content not full <html> content

When I perform a Request.HTML through mootools, the responseHTML property only contains the contents of the tag and not the full content that can be found in the response body.

Can anyone explain why - and if it is possible to retrieve the full HTML? I've got an existing application which requests an "email preview" via ajax and then drops the response into an iframe but recently the iframe has lost the CSS and it is due to the Request.HTML's responseHTML property not containing the full html.

Here is a JSFiddle: http://jsfiddle.net/BloodBaz/n7nwhkc9/3/

Thanks, Chris

Upvotes: 4

Views: 541

Answers (1)

Dimitar Christoff
Dimitar Christoff

Reputation: 26165

Request.HTML was conceived as a way to retrieve fragments, like templates/partials and convert into a node tree.

It makes sense to skip <head /> in that context, as injecting styles, scripts etc may be completely undesired - you can see it here https://github.com/mootools/mootools-core/blob/master/Source/Request/Request.HTML.js#L38, where the context is being shifted into body, if there is one.

the script tags from the body are also extracted and put aside, run if evalScripts is set to true.

You don't need to use Request.HTML if you care about the full body and not the parser, just use Request() or reference this.response.text property in your success handler.

for instance: http://jsfiddle.net/dimitar/n7nwhkc9/5/

you should still not use Request.HTML if you don't rely on the xml parser to get you the node tree.

Upvotes: 4

Related Questions