The server and client side are still segregated. In that other post Meteor.call
is used to relay the message to the server to do a request there and return the scrape result back to the client.
The error you're getting is due to javascript being asynchronous on the browser side of things. More info about that here & here. You need to use a callback with client side code because it takes time to fetch data from the server.
Is this your intention to run the http request off the client? On the client there are issues such as the Access-Control-Allow-Origin.
. Which is why on that post a Meteor.call
is done to the server to proxy the request through and return the data to the client.
In your click handler you could use the code at How can one parse HTML server-side with Meteor? with:
Template.entry.events = {
'click .btn_scrape' : function() {
$('.btn_scrape').attr('disabled','disabled')
Meteor.call("last_action",function(err,result){
$('.btn_scrape').removeAttr('disabled')
console.log(result);
});
}
}
In the Meteor.isServer
section of your code you would still need the method last_action
to proxy the data to your browser:
var cheerio = __meteor_bootstrap__.require('cheerio');
Meteor.methods({
last_action: function() {
$ = cheerio.load(Meteor.http.get("https://github.com/meteor/meteor").content);
return $('.commit-title').text().trim()
}
})