我想将一些JSON发布到我的。
JSON看起来是这样的:
{
"name": "John Doe",
"socials": {
"facebook": {
"uid": "1234321",
"fbsrCookie": "sdfsdfhgsd"
}
}
}安博的邮政电话看起来是这样的:
Ember.$.post('http://localhost:3000/register', data).then(function ...使用Firefox的Developer-Tools检查消息显示,参数如下
name: "John Doe"
socials[facebook][uid]: "1234321"
socials[facebook][fbsrCookie]: "sdfsdfhgsd"由于标题“Content”,即“application/x form-urlencoded;charset=UTF-8”,我无法处理node.js-后端(因为它不是JSON)中的值。
有办法从服务器-(node.js)-backend读取属性吗?或者如何以JSON的形式发送有效负载?
发布于 2015-08-15 16:06:04
好的,就像@sdgluck提到的那样,press.js-Framework(我正在使用的)还可以解析我在上面的问题中所列的表单数据(url编码)参数。因此,我再次检查了express.js的bodyParser中间件的包含,并将“扩展的”-Parameter更改为true,如下所示:
app.use(bodyParser.urlencoded({
extended: true
}));现在,express.js还解析参数,让我通过点表示法(如:req.body.socials.facebook.uid)访问它们。
感谢@sdgluck!
发布于 2015-08-15 18:00:08
如果您有一个返回json的REST服务器,那么将其发送到application/json
vara data = {
"name": "John Doe",
"socials": {
"facebook": {
"uid": "1234321",
"fbsrCookie": "sdfsdfhgsd"
}
}
}
Ember.$.ajax({
method: "post",
contentType: 'application/json',
data: JSON.stringify(data)
});https://stackoverflow.com/questions/32026338
复制相似问题