我正在开发API使用meteor软件包,我想发布数据,并希望保存在数据库中。我已经完成了以下编码,但无法在api调用中得到发布的数据。
// made post api using restivus
Restivus.configure({
useAuth: false,
prettyJson: true
});
Restivus.addRoute('addorder', {authRequired: true}, {
post:{
action: function (data) {
console.log(data); // undefined
return {status: "success", data: "test"};
}
}
});上面的api是我使用服务器端方法调用的,因此我已经完成了以下编码。
Meteor.methods({
apiInsert:function (name){
this.unblock();
console.log("api insert method");
var url = "http://localhost:3000/api/addorder";
var result = HTTP.post(url,{
data: { "name": name },
headers:{
"content-type":"application/json ; charset=UTF-8",
}
});但是我不会在api函数中得到发布的数据,而是在数据变量中得到未定义的数据。我不知道如何在api函数中检索已发布的数据。
发布于 2015-06-09 13:34:25
尝试使用this.bodyParams。
post: {
action: function () {
return {status: 'success', data: this.bodyParams};
}https://stackoverflow.com/questions/30572961
复制相似问题