【发布时间】:2016-09-21 10:39:38
【问题描述】:
我正在使用这样的方式发布到快速应用程序:
$.ajax
type: "POST"
url: localUrl
data: data
cache: false
dataType: 'native'
xhrFields:
responseType: 'blob'
这就是data 的样子:
data =
'options':
'format': 'Letter'
'border':
'top': '2in'
'right': '1in'
'bottom': '2in'
'left': '1.5i'
'header':
'height': '45mm'
'contents': header
当我在 Express 应用程序中记录 req.body 时,结果如下所示:
{
'options[format]': 'Letter',
'options[border][top]': '2in',
'options[border][right]': '1in',
'options[border][bottom]': '2in',
'options[border][left]': '1.5i',
'options[header][height]': '45mm',
'options[header][contents]': '<div class="pdf-header">\n\tChart generated by http://collab.craft.dev\n</div>',
'options[footer][height]': '28mm',
'options[footer][contents]': '<div class="pdf-footer">\n\tTue May 24 2016 10:32:36 GMT+0100 (BST)\n</div>'
}
这意味着我无法使用req.body.options.border.top 访问(例如)border.top 属性。
这里发生了什么,如何确保对象结构得到维护?
非常感谢!
【问题讨论】:
-
req.body.options.border.top不会工作? -
很遗憾没有。我认为是因为对象结构被折叠成我上面打印的格式。我意识到我打错了。现已编辑。