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

113
Vistas
jQuery selecting data value from fetch

I came across another issue with jquery. I seen code that uses .ajax() method and the response is being selected like this

.then(response => {
  $(response).find('.some-selector')
})

This is really confusing me.

I did a refactor to vanilla js like this

fetch('/some-endpoint', {
  method: 'POST',
  body: new FormData(e.currentTarget)
})
.then(res => res.text())
.then(data => {
  data.querySelector('.some-selector') // does not work
})

Everything is working, the response is good, but I do not understand how to get the selected value from the data.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to parse the response first:

fetch('/some-endpoint', {
  method: 'POST',
  body: new FormData(e.currentTarget)
})
.then(res => res.text())
.then(function(html) {
  const parser = new DOMParser();
  return parser.parseFromString(html, "text/html");
})
.then(data => {
  data.querySelector('.some-selector');
})

about 4 years ago · Juan Pablo Isaza Denunciar
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