错误:Route.put()需要回调函数但得到一个[object String]

时间:2017-02-08 06:14:01

标签: node.js

我在eclipse中执行代码时遇到此问题,下面是我的代码。我只创建了两个get和put方法。 get()方法工作正常put()显示错误消息。

.put('/:employeeId/update',function(req, res) {
        // Get our REST or form values. These rely on the "name" attributes
        var empName = req.body.empname;
        var empSalary = req.body.salary;
       var empId = req.params.employeeId;
       console.log("Emp Name::"+empName);
        //find the document by ID
        mongoose.model('Employee').findOne({"empid":empId}, function (err, employee) {
            //update it
            employee.update({
                empname : empName,
                empsalary : empSalary,
            }, function (err, empid) {
              if (err) {
                  res.send("There was a problem updating the information to the database: " + err);
              } 
              else {
                      //HTML responds by going back to the page or you can be fancy and create a new view that shows a success page.
                      res.format({
                          html: function(){
                               res.redirect("/blobs/" + employee.empid);
                         },
                         //JSON responds showing the updated values
                        json: function(){
                               res.json(employee);
                         }
                      });
               }
            })
        });
    });

0 个答案:

没有答案