admin管理员组文章数量:1178529
So, I'm trying to write a method that makes an http call. When I run the method, I get the following error:
Exception while invoking method 'upload' TypeError: Cannot call method 'call' of undefined
Here is what the code looks like:
Client:
console.log(Meteor.call('upload', f, content));
Server:
Meteor.methods({
upload: function(file, content) {
this.unblock();
Meteor.http.call("PUT", "http://blah");
}
});
UPDATE: Problem solved, turns out I had to enable the package: meteor add http
So, I'm trying to write a method that makes an http call. When I run the method, I get the following error:
Exception while invoking method 'upload' TypeError: Cannot call method 'call' of undefined
Here is what the code looks like:
Client:
console.log(Meteor.call('upload', f, content));
Server:
Meteor.methods({
upload: function(file, content) {
this.unblock();
Meteor.http.call("PUT", "http://blah");
}
});
UPDATE: Problem solved, turns out I had to enable the package: meteor add http
2 Answers
Reset to default 41You simply need to add the HTTP package by running this on command line in your project :
meteor add http
Also you need a call back using Meteor.call client side.
From the documentation:
On the client, if you do not pass a callback and you are not inside a stub, call will return undefined, and you will have no way to get the return value of the method. That is because the client doesn't have fibers, so there is not actually any way it can block on the remote execution of a method.
So you should change this
console.log(Meteor.call('upload', f, content));
to this
Meteor.call('upload', f, content, function(error, result){console.log(result);});
本文标签: javascriptMeteorhttp method is undefined on serverStack Overflow
版权声明:本文标题:javascript - Meteor.http method is undefined on server? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737998793a2046871.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Meteor.http
evaluates to undefined ... where's the issue/question? A question would be: "Why is Meteor.http not a function?" or some such. This is just debugging.) – user166390 Commented Apr 21, 2012 at 23:52Meteor.http
<-- what does that result in? It'll beundefined
so ... why? Where was it defined? – user166390 Commented Apr 22, 2012 at 0:07