I'm using request.js to download the content of a web page, but I need to wait until the dom is completely loaded before using it. Here is my code:
function requestPage(id) {
var options = {
method: 'GET',
gzip: true,
url: 'xxx' + id,
headers: getHeaders
}
request(options, function(error, response, body) {
if (response.statusCode == 200) {
generatePDF(generateHTML(body, id),id)
}
})
}
How can I wait until everything is loaded before using the response in my generateHtml function?