成功进行mongoose保存后出现Ajax错误

时间:2016-02-07 09:18:51

标签: javascript jquery ajax node.js mongodb

希望有人能帮助我。 使用Mongoose成功保存()之后,对Ajax的res会产生错误。 它到达console.log但它在我的Ajax中返回错误。

提前致谢

app.post('/api/addItem', function (req, res) {
    var newProdukt = new Produkt(req.body);
    newProdukt.save().then(function(data){
        console.log('added');
        res.json(data);
    },function(e){
       res.json(e);
    });
});

  $.ajax({
        url:'api/addItem',
        data:createNewItem(),
        type:'POST',
        dataType:'json',
        success:function(data){
            alert(data);
        },
        error:function(e){
            alert("error");
        }
    });
}

0 个答案:

没有答案