After referring to this helpful post, I am attempting to utilize ajax to load a document and extract specific content nodes in order to display them without needing to reload the browser.
Unfortunately, every time I try, the document appears to be empty.
Here is my Ajax callback code:
function processRatingToken(data) { //Data is just standart HTML document string
var doc = document.implementation.createHTMLDocument();
doc.open();
//Replace scripts
data = data.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");
//Write HTML to the new document
doc.write(data);
doc.close();
console.log(doc.body); //Empty
}
What could be causing this issue?
Note: My reason for using this approach is because I am creating a Greasemonkey Userscript. For those developing an Ajax application, it is recommended to use JSON instead of this method.