i need to get the value of the input with javascript.
Input:
<input id="user_id" value="5" name="user_id" type="hidden">
Controller:
public function savetoken(Request $request)
{
$this->validate($request, [
'user_id' => 'required',
'token' => 'required',
]);
Notificaciones::create([
'user_id' => $request->user_id,
'token' => $request->token
]);
return back()->with('success', 'token saved successfully!');
}
How to get the Value of the Input that is Hidden? Javascript:
function guardarToken(token){
var formData=new FormData();
formData.append('token',token);
formData.append('user_id', user_id);
var config = {
headers: {
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"').content
}
}
axios.post('/token',formData, config).then( respuesta=>{
console.log(respuesta);
}).catch( e=>{
console.log(e);
});
}
I tried this way but I have not succeeded
help please
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire