Reputation: 173
I update the database with jquery ajax and print "success/failure" with alert according to the return value. The product update is successful, but the message "failed" appears on the screen and I get the error "The PUT method is not supported for this route".
My 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>
coming here by route:
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!');
}
Upvotes: 0
Views: 394
Reputation: 175
Change the method to POST.
$.ajax({
type: 'POST',
data: $('#bulkupdate_form').serialize(),
url: url,
...
});
Considering that csrf token is not been included in the headers yet, you must include it on form data:
<form id="bulkupdate_form" ... >
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<!-- or simply -->
@csrf
</form>
Upvotes: 1