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

315
Views
Espere la entrada de Sweet Alert si se cumple una condición; de lo contrario, continúe

Tengo este script, que en algunos casos puede requerir la entrada del usuario. Funciona, pero el script continúa independientemente del resultado de la entrada Sweet Alert.

 $('#cart').on('click', '.button', function() { var code = $(this).data('code') if ((code !== '') && (code !== null) && (code !== undefined)) { var repeated = 0 var secondary = null if (code.startsWith('ABC')) { swalBs.fire({ text: 'Enter secondary code', showCancelButton: true, cancelButtonText: 'Cancel', showConfirmButton: true, confirmButtonText: 'Confirm', reverseButtons: true, input: 'text', inputValidator: (value) => { if (!value) { return 'Code required' } } }) .then((result) => { console.log(result) secondary = result.value }) } if (repeated < 1) { $.post(serviceUrl, { c : code, s : secondary }, function(response) { ... }) .fail(function() { ... }) } else { swalBs.fire('Error', 'Code already entered', 'error') } } else { swalBs.fire('Enter code', 'Field must not be blank.') } })

¿Cómo puedo hacer que este script espere la entrada de Sweet Alert y al mismo tiempo permita que $.post suceda cuando no se cumple la condición if (code.startsWith('ABC')) (y no se necesita Sweet Alert)?

about 4 years ago · Juan Pablo Isaza
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!