【发布时间】:2012-08-13 06:07:16
【问题描述】:
我正在向 node.js 发送带有以下请求的凭据 JSON 对象:
credentials = new Object();
credentials.username = username;
credentials.password = password;
$.ajax({
type: 'POST',
url: 'door.validate',
data: credentials,
dataType: 'json',
complete: function(validationResponse) {
...
}
});
在服务器端,我想将提交的凭据加载到 JSON 对象中以进一步使用它..
但是,我不知道如何从 req 对象中获取 JSON...
http.createServer(
function (req, res) {
// How do i acess the JSON
// credentials object here?
}
).listen(80);
(我的函数(req, res)中有一个调度程序将 req 进一步传递给控制器,所以我不想使用 .on('data', ...) 函数)
【问题讨论】: