我想从js文件到laravel路由做一个jquery的帖子,但似乎它不工作,我不知道为什么。jquery post调用路由laravel不工作
我的主要目标是:从一个复选框被选中的表中获取所有ID,并在SQL上更改它们的列值。
所以,这里是我的JS功能:
function concludeAll() {
var arrayIds = [];
$('.checkbox1').each(function() {
var $this = $(this);
var $id = $this.attr('id');
if ($this.is(":checked")) {
arrayIds.push($id);
}
});
var json = {
"ids": arrayIds
};
$.post('http://localhost:8000/controle/pending/concludeAll',
{
'_token': $('meta[name=csrf-token]').attr('content'),
ids: arrayIds
})
.error(
)
.success(
);
}
这是我的路线:
Route::group(['prefix' => '/controle'], function() {
Route::post('/pending/concludeAll/', function() {
$input = Input::only('ids');
$input = $input['ids'];
foreach($input as $id) {
$student = new App\Aluno();
$student = $student->where('id', '=', $id)->first();
$student->pending = '0';
$student->save();
}
}); };
所以,如果我检查表上的几行,撞上调用该函数按钮,我的控制台没有任何反应。上网络>头>形式数据I看到的令牌和的ID,如下所示:
_token:fNWunwF8yDLSycrkBE684wgQcyK9dP8wbR7VgLjC IDS []:23个 IDS []:20
上预览,我看到我是完全一样的页面。 作为回应,我看到了页面的HTML。
我也试过dd($ input);在路线上,但没有什么不同发生..
尝试php工匠路线:清除和没有什么不同发生。
如果我更改URL为http://localhost:8000/controle/pending/concludeAll2的名称,返回任何错误,这让我疯狂......
任何想法如何让这个帖子调用路线?谢谢!
转换你的'arrayIds'成JSON'IDS:JSON.stringify(arrayIds)'然后看.. –
如果你的控制台没有任何反应,你怎么看到这些头文件? – Devon
@HimanshuUpadhyay它唯一的区别是:在网络>标题>表单数据我看到ids:[“23”,“20”,“29”],而不是ids []:23 ids []:20。我认为这是必要的,但还没有解决问题。不过谢谢。 –