Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

352
Visualizações
When I correct the invalid input(s) and try to submit again, the code will not execute

I have this code in javascript/jquery which takes input from a form with ID #account-save and is using ajax ajax_send.submit(false, action, data, account_save); to submit data to the server.

The following code will successfully submit the data. If the data submitted contains invalid inputs, the code below receive html that marked red those inputs containing the invalid data.

(function($, undefined) {
  "use strict";

  $(function() {
    $("#account-save").click(function(e) {
      var action = $(this).data('action') + '/edit';
      var data   = { 'form_data': $('#user-profile').serialize() }
      ajax_send.submit(false, action, data, account_save);
    });
  });

  function account_save(result = false) {
    if (result != false) {
      $('#user-profile').html(result.html);
    }
  }
})(jQuery);

The problem is, when I correct the invalid input(s) and try to submit again, the code above will not execute.

Is there anyone have the same problem? Any help would be appreciated.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I think that when your html is being sent back, it is replacing the #account-save node entirely, meaning it has essentially been removed from the DOM as far your your .click method is concerned.

Change your $(document).on('click', '#account-save', function(e) to make to make it late binding. This way your event listeners can attach themselves to elements added to the DOM

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda