Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
Get Data from Input Field into Fetch Request in JavaScript

I am trying to get the data from a text field into my fetch request so that I can get a response from an API. The data should be sent to the fetch request onsubmit or onchange

How can I go about it?

HTML:

<div class="input-field">
    <input type="text" id="data" placeholder="submit token">
</div>

JS:

function dataFetch(url) {

  const data = document.getElementById("data").value;
  const myHeaders = { "x-data-token": data,
"x-data-access": "all-access")
}

  const requestOptions = {
    method: "GET",
    headers: myHeaders,
  };

  fetch(url, requestOptions)
    .then((res) => (res.ok ? res.json() : Promise.reject(res)))
    .then((data) => {
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda