Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
Javascript: la variable no nula se vuelve indefinida después de la función de búsqueda + problema de encabezados

Hola, tengo problemas para usar la función de búsqueda, en este momento quiero cambiar los encabezados después de un inicio de sesión usando el token 'l' para que tenga éxito si es un usuario real. Este es el código:

varl; //variable que uso para poner el token en el futuro

Acceso

 const login = document.getElementById('login'); const nome = document.getElementById('lnome'); const pass = document.getElementById('lpass'); const item = { Username: nome.value.trim(), Password: pass.value.trim() }; fetch(uri_2, { credentials: 'include', method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify(item) }) .then(response => { //check in the response if is a user, otherwise do catch }) .then((res) => { nome.value = ''; pass.value = ''; window.alert('Login Bem Sucedido :'); //HERE I HAVE PROBLEM PUT THE TOKEN, THIS CODE IS WRONG //setRequestHeader("Authorization", 'Bearer ' + l); headers: new Headers({ 'Authorization': 'Basic ' + btoa('username:password'), 'Content-Type': 'application/x-www-form-urlencoded' }), //HERE I PUT THE TOKEN IN A VAR L l = res; window.location.href = url_1; }) .catch(error => { //here i have a bunch of alerts to check if is a valid user }); }

Lista de páginas después de iniciar sesión

 $(function () { var $users_A = $('#users_A'); debugger; $.ajax({ url: uri_3_2, type: 'GET', dataType: 'json', //HERE IS WHEN I NEED TO PUT THE TOKEN beforeSend: function (request) { request.setRequestHeader("Authorization",'Bearer '+l); }, success: function (data) { console.log('Sucess YAYYYYYYYY'); }, error: function (xhr, textStatus, errorThrown) { console.log('Error in Operation'); } }); });

Hice depuración en ambas funciones y para mi sorpresa, antes de llamar al método ajax, puedo poner el token en la variable l PERO después del método ajax, no está definido el token y no entiendo por qué, es por usar buscar y, por otro lado, usar ajax, ¿es por los encabezados de la búsqueda o por otro error?

Cualquier respuesta es bienvenida.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!