php - PHP从jQuery发送空时未接收POST数组
问题描述
我正在使用 Laravel。当我dd($request->all())
只在数组不为空时打印数据,即Array['some-value']
。当我console.log(data)
在 jQuery 中时,它会在控制台中记录它是一个数组,但里面没有任何值。但是在 Laravel 中我无法得到那个空数组,但是当它有价值时我可以得到它。我想发送数组,即使它是空的。
我怎样才能做到这一点?
更新
HTML:
<ul>
<!-- It sends but doesn't show in Laravel when this active class below is not exists -->
<li class="active" data-motion="1">motion 1</li>
<li data-motion="2">motion 2</li>
<li data-motion="3">motion 3</li>
</ul>
jQuery:
$.each($('ul li.active'), function(index, motion) {
motion = $(motion).attr('data-motion');
params['motions'].push(motion);
});
// it shows the empty array when that active class is not there,
// which is the one I want to get in Laravel too.
consol.log(params);
$.ajax({
url: '/my-motions',
type: 'PUT',
dataType: 'json',
data: params,
success: function(response) {
params = [];
},
error: function(error) {
//
}
});
拉拉维尔:
public function myFunc(Request $request)
{
$data = $request->all();
dd($data);
// The result: nothing
// What I want: array:0 []
}
解决方案
推荐阅读
- reactjs - 子组件渲染时如何触发useEffect?
- spring - 无论在何处定义,如何在 Spring Boot 应用程序中获取有效的属性?
- xml - 多行上的 sed 替换
- swift - CGAffineTransform 不适用于自定义 UIView
- flask - Git 实验室 CI 使用 SqlAlchemy 进行鼻子测试。错误:失败:TypeError(无法将此 __setattr__ 应用于 DefaultMeta 对象)
- git - 从压缩文件更新 git 分支
- r - 从 R 中的单个单元格中删除异常值
- regex - 正则表达式不一致
- c++ - 有没有办法在 c++ 中使用 c-union 风格的类型双关语?
- r - 保持第 1 行不变 聚合接下来的三个