jquery ajax 更新后出现"PUT method is not supported for this route"错误



我用jquery ajax更新数据库并打印"成功/失败";根据返回值发出警报。产品更新成功,但消息";失败";出现在屏幕上并且我得到错误";PUT方法不支持该路由";。

我的jquery:

$('#policies_button').on('click', function () {
$('#ShiftAddModal').modal('hide');
var id = $('#select_policies').val();
var url = $('#selected_option_' + id).attr('data-url');
$.ajax({
type: 'PUT',
data: $('#bulkupdate_form').serialize(),
url: url,
success: function (response) {
if (response.success) {
$('#ShiftAddModal').modal('hide');
alertify.success('Başarılı: İzin kuralı ataması başarılı bir şekilde gerçekleşmiştir.');
} else if (response.error) {
alertify.error(response.error);
}
},
error: function (e) {
alertify.error('Hata: Sayfanızı yenileyerek tekrar deneyiniz.');
}
});
});

url:

<option id="selected_option_{{$item->policies_id}}"
value="{{$item->policies_id}}"
data-url="{{route('personnel.update',$item->policies_id)}}">{{$item->name}}</option>

通过以下途径来此:

protected function policiesAction(Request $request, $id)
{
foreach ($this->model->get() as $item) {
$action = Actions::personnel_policies_update(
$this->model,
$request->get('personnel_name' . $item->personnel_id),
$id
);
}
return $action;
}

public static function personnel_policies_update(Model $model,$personnel_id,$id){
$fields = array(
'policies_id' => $id,
);
$model->where('personnel_id',$personnel_id)->update($fields);
return redirect()->to(route('bulkupdate.index'))->with('success','Başarılı: Personel ataması başarıyla gerçekleşti!');
}

将方法更改为POST。

$.ajax({
type: 'POST',
data: $('#bulkupdate_form').serialize(),
url: url,
...
});

考虑到csrf令牌尚未包含在标头中,您必须将其包含在表单数据中:

<form id="bulkupdate_form" ... >
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<!-- or simply -->
@csrf        
</form>

相关内容

最新更新