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

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

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