【发布时间】:2016-03-10 15:14:12
【问题描述】:
我在 ReactJs 中有一个 http put 函数,看起来像这样
UpdateItem: function(_id) {
var input = this.refs.myInput;
$.ajax({
url: 'http://localhost:3000/update/' + _id,
type: 'PUT',
data:input,
cache: false,
success: function(result) {
console.log(data);
window.location.reload();
}
});
}
它需要一个输入,它应该随请求发送新值,但它永远不会这样做
<input ref="myInput" type="number" name="quantity" min="1" max="10" defaultValue={item.quantity} className="form-control"/>
当我查看控制台时,req.body 显示了这个 [object Object],我在节点中的 put 函数看起来像这样
app.put('/update/:_id', function(req, res) {
console.log(req.params);
console.log("your req is" +req.body);
Cart.findByIdAndUpdate(req.params.id, { quantity: req.body.quantity }, function(err, product) {
if (err) throw err;
console.log(product);
console.log(product);
});
});
对可能出现的问题有什么想法吗?
【问题讨论】:
标签: javascript node.js express reactjs