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?
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() }); ... }); });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); });