I need your help to solve this error, it appeared out of nowhere, it was working normally, and now I don't know why I get this error with the X-CSRF-TOKEN. My head:
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
My script:
<script>
const csrfToken = document.head.querySelector('meta[name="csrf-token"]').content;
document.getElementById('_categoria').addEventListener('change',(e)=>{
fetch('subcategorias',{
method : 'POST',
body: JSON.stringify({texto : e.target.value}),
headers:{
'Content-Type': 'application/json',
"X-CSRF-Token": csrfToken
}
}).then(response =>{
return response.json()
}).then( data =>{
var opciones ="<option value=''>Elegir</option>";
for (let i in data.lista) {
opciones+= '<option value="'+data.lista[i].id+'">'+data.lista[i].nombre+'</option>';
}
document.getElementById("_subcategoria").innerHTML = opciones;
}).catch(error =>console.error(error));
})
document.getElementById('_subcategoria').addEventListener('change',(e)=>{
fetch('empresas',{
method : 'POST',
body: JSON.stringify({texto : e.target.value}),
headers:{
'Content-Type': 'application/json',
"X-CSRF-Token": csrfToken
}
}).then(response =>{
return response.json()
}).then( data =>{
var opciones ="<option value=''>Elegir</option>";
for (let i in data.lista) {
opciones+= '<option value="'+data.lista[i].id+'">'+data.lista[i].nombre+'</option>';
}
document.getElementById("_empresa").innerHTML = opciones;
}).catch(error =>console.error(error));
})
I clarify that the script is for dynamic selects of 3 levels.