Please help me for this case. I try to import or pass data from asynchronous function to client side.
Event i use session on server the client still cannot get value from that session also.
Meteor.methods({
searchResult: function() {
if (Meteor.isServer) {
this.unblock();
var result = HTTP.call(‘GET’, ‘http://localhost:9200/store/product/_search’);
Session.set(‘resultData’, result.statusCode);
}
}
});
And console.log(Session.get(‘resultData’)
the result of console.log still undefined
Any idea on this case please help me. Thanks advanced
If you put your methods in a file under a server/ folder you don’t need to use if (Meteor.isServer). You should probably also avoid this.unblock() - it won’t necessarily provide any benefit here.
This is how it could be done.
In server/methods.js:
Meteor.methods({
searchResult() {
var result = HTTP.call('GET', 'http://localhost:9200/store/product/_search');
return result;
}
});
Then, in your client code (in a file under a client/ folder):
Meteor.call('searchResult', (error, result) => {
if (error) {
console.log('something broke');
} else {
console.log(result); // result is available here
}
});
If you want to use the result outside of that callback you will likely need to use a reactive variable.
Hello, Robfallows,
I ready change create file name: methods.js inside folder server, unfortunately i cannot call the method that i just created.
The error: cannot find method name "searchResult"
meteor version 1.4