【发布时间】:2016-03-05 13:52:41
【问题描述】:
当我单击 angular 侧的按钮时,我正在使用 nodejs 和 angular,它会生成一个 json 帖子,但由于跨域问题,我使用 JSONP。当我尝试通过 JSONP 获取从客户端发送的数据时,我得到了这样的结果;
{ '{"userName": "something", "password" : "123"}': '' }
我从 server.js 上的 req.body 获取它。
这是我的服务器端代码
app.post('/', function(req,res){
console.log("consoleeee:" + req.body);
res.end();
});
我的客户端功能在单击按钮时起作用
function loginPageLogin(a, b, c, d, e, f, g, h, i, j) {
$.ajax
({
type: "POST",
url: 'http://localhost:777/node',
dataType: 'jsonp',
async: false,
data: '{"userName": "' + a.value + '", "password" : "' + b.value + '"}'
})
如何正确获取 req.body?我想要它作为对象。谢谢...
【问题讨论】:
-
JSONP 适用于 GET 而不是 POST