仍在努力让我与Meteor立足。我需要一种类似于AJAX的方法来触发服务器上的某些内容,并获得已完成的响应。
我想做的是这样的:
Router.map(function() {
// Remove Blog Posting
this.route('blogRemove', {
path: '/blogRemove/:_id',
where: 'server',
handler: function() {
var request = this.request;
var response = this.response;
// Do some deleting here
}
});
});
这将触发一些服务器调用,以删除具有给定的博客_id
。然后,我将通过该response
对象以JSON进行回复。但是经过15年的开发工作,我了解到:仅仅因为有可能,并不意味着这是正确的方法...
因此,问题是:对于AJAX类型的调用,这是在Meteor / Iron Router中进行流式处理的首选方式,还是有一些更有效/更优雅的方式来进行处理?
通常,您将为此使用流星方法。例如:
服务器:
Meteor.methods({
blogRemove: function (id) {
// delete the blog
return {status: "OK", msg: "removed blog " + id};
}
});
客户:
Meteor.call('blogRemove', id, function(err, result) {
console.log(result);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句