【发布时间】:2014-02-25 13:01:15
【问题描述】:
用.post的FORM数据到express/node.js
所有值当前都以字符串形式存储和返回
希望将其中一个数据值 (req.body.quantity) 存储为 INT
//POST
app.post('/add', function (req, res) {
db.collection('demo').insert(
{
"title" : req.body.title,
"quantity" : req.body.quantity,
},
function (err, doc) {
getAll(res);
});
});
getAll 当前如下所示:
//EXPRESS NODE.JS
function getAll(res) {
db.collection('demo').find().sort( { quantity: 1 } ).toArray(function (err, docs) {
// each doc should look like: { title: 'string', quantity: int}
res.json({docs: docs});
});
}
还有工作的.get:
// AJAX
$('#getBtn').click(function() {
$.get('http://localhost:9999').
done(gotAllSuccess).
fail(gotAllFailure);
});
【问题讨论】:
标签: jquery ajax json node.js mongodb