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

175
Views
convertir una llamada fetch api a ajax

estoy usando un código de un sitio donde se realiza la llamada onsubmit y se realiza una llamada

 $(":submit").click(async (event) => {

No estoy al tanto de esta sintaxis.

mi ejemplo usando la simple llamada $.ajax y haciendo una llamada posterior a la página

por lo que la función anterior es así

 $(":submit").click(async (event) => { event.preventDefault(); let response = await fetch("page.cfm"); const reader = response.body.getReader(); const len = response.headers.get("Content-Length") * 1;

mi llamada ajax es así

 $.ajax({ url: "page.cfm", cache: false, data : $('#form').serialize(), method: "post", beforeSend: function() { $('div.results').html('Please wait'); }, success: function(response){ $('div.results').html(response); }

¿Cómo puedo formatear lo anterior en mi llamada ajax?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Incluir datos de formulario en el cuerpo. Asegúrese de que su búsqueda en espera esté dentro de las funciones asíncronas.

 $('document').ready( async function() { $("#test_fetch").submit( async function(e) { e.preventDefault(); // avoid to execute the actual submit of the form. var form = $(this); var url = form.attr('action'); let response = await fetch(url,{ method:"post", body: $(form).serialize() }); ... }); });
about 4 years ago · Juan Pablo Isaza Report

0

Tienes que cambiar la solicitud a POST y pasar los datos.
Luego lea los datos de la respuesta.

 $(":submit").click(async (event) => { event.preventDefault(); $('div.results').html('Please wait'); let response = await fetch("page.cfm", {method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: $('#form').serialize()}); const html = await response.text(); $('div.results').html(html); });
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!