【发布时间】:2019-10-09 12:51:15
【问题描述】:
我有这个价格数组,像这样:
<input type="input" id="prices[type][1]" name="prices[type][1]">
<input type="input" id="prices[type][2]" name="prices[type][2]">
我通过发布请求(JSON:是的,Content-Type 设置为 application/json)发送此数据,并在我使用 $request->input('prices') 时期望得到一个数组,但这并没有真正发生。也试过$request->get('prices')。
当我$request->all() 时,我确实得到了我提交的所有数据:
用于发出请求的JS:
const response = await fetch(this.action, {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': this.$page.token,
},
body: this.formData(),
});
const body = await response.json();
this.formData():
formData(): Object {
const formData = new FormData(this.$el);
return JSON.stringify(Array.from(formData.entries()).reduce((memo, pair) => ({
...memo,
[pair[0]]: pair[1],
}), {}));
},
有人知道哪里可能出错吗?
【问题讨论】: