documentclient put无法正常工作,尝试了一切

时间:2017-09-20 00:33:52

标签: amazon-web-services express amazon-dynamodb

我的hashkey是一个名为pid的数字

这是代码

app.get('/register', (req, res) => {

var params = {
  TableName:"passengers",
  Item: {
    "pid": 55
  }
};

console.log("Adding a new item...");
docClient.put(params, function(err, data) {
  if (err) {
    console.log("errrrrrrr");
    console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
  } else {
    console.log("succccccc");
    console.log("Added item:", JSON.stringify(data, null, 2));
  }
});
console.log("Added a new item...");

res.send('<h1>some html</h1>');


})

errrr或succcc都没有打印在日志中,但都是&#34;添加新项目&#34;和&#34;添加了一个新项目&#34;打印出来。

1 个答案:

答案 0 :(得分:0)

正如评论中所述,IonicPage import API是异步的。因此,当put成功或失败时,您应该将响应返回给客户端。

请在回拨方法中加入put。 Alos,请使用HttpMethod POST 来放置项而不是 GET 方法。我希望你刚刚将它用于快速测试目的。

res.send
相关问题