Una pregunta AJAX no encontrada con el formulario modal html y bootstrap
Publicado por Angel (12 intervenciones) el 08/06/2021 16:34:58
Tengo problemas con una solicitud posterior a AJAX y no sé qué está mal. Tengo una ventana modal que funciona correctamente y quiero pasar los valores de entrada a la función update_register en mi controlador.
Gracias de antemano
blade.php (Only the modal form and the request ajax petition. If you need more tell me)
Modal form
La peticion AJAX:
funcion controlador (el nombre de la ruta es : update_register)
Gracias de antemano
blade.php (Only the modal form and the request ajax petition. If you need more tell me)
Modal form
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<div class="modal fade" id="edit-user" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="update_modalform">
@csrf
<div class="form-group row">
<label for="name"
class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name_update" type="text" class="form-control @error('name') is-invalid @enderror"
name="name" value="{{ old('name') }}" required autocomplete="name"
autofocus>
@error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-group row">
<label for="username"
class="col-md-4 col-form-label text-md-right">{{ __('username') }}</label>
<div class="col-md-6">
<input id="username_update" type="text"
class="form-control @error('username') is-invalid @enderror" name="username"
value="{{ old('username') }}" required autocomplete="username">
@error('username')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
La peticion AJAX:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$('#update_modalform').submit(function (e) {
e.preventDefault();
const name = $('#name_update').val();
const username = $('#username_update').val();
const email = $('#email_update').val();
const password = $('#password_update').val();
const token = $('input[name=_token]').val();
const confirm_password = $('#password-confirm_update').val();
if (password == confirm_password) {
$.ajax({
url: "/admin/update-register",
method: "POST",
data: {
name: name,
username: username,
email: email,
password: password,
_token: token
},
success: function (res) {
if (res) {
$('#edit-user').modal('hide');
toastr.info('El registro fue actualizado correctamente',
'Actualizar Registro', {
timeout: 3000
});
$('#edit-user').DataTable().ajax.reload();
} else {
toastr.warning('Ha habido un error', 'Actualizar Registro', {
timeout: 3000
});
}
}
})
}
})
funcion controlador (el nombre de la ruta es : update_register)
1
2
3
4
5
6
7
8
9
10
function update_register(Request $request)
{ // Query to edit user
$data = [$request->name, $request->username, $request->email, $request->password];
$hashed_password = Hash::make($data[3]);
DB::table('users')
->where('email', $data[2])
->update(['name' => $data[0], 'username' => $data[1], 'email' => $data[2], 'password' => $hashed_password, 'updated_at' => date('Y-m-d G:i:s')]);
return back();
}
Valora esta pregunta


0