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

324
Vistas
Uncaught TypeError: jQuery(...).submit(...) .then is not a function

I have a problem with my code, capturing the data from a form and then submitting it by a POST using Fetch, however, I have this error in the console:

Uncaught TypeError: jQuery (...). Submit (...). Then is not a function

Some developer could guide me, I would really appreciate it

PS: I am not a developer, I work in digital marketing

jQuery('form').submit(function() {
    var $form = jQuery(this);
    var email = $form.find("input[name='email']").val();
    const userID = "id" + Math.random().toString(16).slice(2);
    var d = new Date();
    var exdays = 365;
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toUTCString();
    document.cookie = "Prodcuto" + "=" + email + "; " + expires + ";path=/";

    dataLayer.push({
      'event': 'Lead',
      'email': email,
      'product': Producto '
    });

    localStorage.setItem('email', email);
    localStorage.setItem('userID', userID);
    localStorage.setItem('ip', ipUser);

    const data = new FormData();
    data.append('email', email);
    data.append('user_id', userID);
    data.append('ip', ipUser);
    fetch('https://webhook.site/aeeaeaee', {
      method: 'POST',
      body: data
    })
  })
  .then(function(response) {
    if (response.ok) {
      return response.text()
    } else {
      throw "Error en la llamada Ajax";
    }
  })
  .then(function(texto) {
    console.log(texto);
  })
  .catch(function(err) {
    console.log(err);
  });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Something like this should work:

async function sendForm(){
  return new Promise((resolve, reject) => {
    jQuery('form').submit(async function() {
      var $form = jQuery(this);
      var email = $form.find("input[name='email']").val();
      const userID = "id" + Math.random().toString(16).slice(2);
      var d = new Date();
      var exdays = 365;
      d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
      var expires = "expires=" + d.toUTCString();
      document.cookie = "Prodcuto" + "=" + email + "; " + expires + ";path=/";

      dataLayer.push({
        'event': 'Lead',
        'email': email,
        'product': 'Producto'
      });

      localStorage.setItem('email', email);
      localStorage.setItem('userID', userID);
      localStorage.setItem('ip', ipUser);

      const data = new FormData();
      data.append('email', email);
      data.append('user_id', userID);
      data.append('ip', ipUser);

      const response = await fetch('https://webhook.site/aeeaeaee', {
        method: 'POST',
        body: data
      })

      resolve(response);
    });
  })
}

try {
  const response = await sendForm();
  if (response.status >== 200 && response.status <== 299) {
    console.log('bueno');
  }
} catch(error) {
  console.log(error)
}
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