Please help me how to create javascript dom from response text, the response text will be like:
<html>
<head >
//scripts and meta tags are av开发者_如何学运维ailable
</head>
<body>
//body content will have html code.
</body>
</html>
I used the below code to create the dom doc:
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(responsetext,"text/xml");
from the doc when i try to get the body content with xmlDoc.body.innerHTML
it
gives null, but the response text have the proper data.
Please help me to get the body content.
-Raja
You tagged this question with jQuery, so I assume you would be open to a jQuery solution?
$(responsetext);
This will give you a jQuery object refering to just the contents of the body element, so $('<html><body><h1>title</h1></body></html>')
gives you a jQuery object referring to a new <h1>title</h1>
element.
Also, where are you getting responsetext
from? I assume it's an AJAX request? Why not use jQuery's ajax functionality and handle the response text in the callback?
Just set the innerHTML of your DOMNode to the responseText
精彩评论