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

115
Views
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 answers
Answer question

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 Report
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!