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

137
Visualizações
Handling error on form submit javascript/jquery/ajax/angularjs

I went through existing questions regarding this topic but I was not able to find a solution for my case. I am new to javascript, jquery. I have this code

let form = angular.element('form');
          form.attr('action', url);
          form.attr('method', 'get');
          form.attr('name', filename);
          if (fieldName != null) {
            $('<input type="hidden" name = "field" value = "' + fieldName + '"/>').appendTo(form);
          }
          form.trigger('submit');

the url is an api call. This performs download of a file. I am trying to handle if there is an error for which I tried using ajax, jquery

let form = angular.element('form');

 form.submit(function(){
            $.ajax({
              async: false,
              url: url,
              type: 'GET',
              cache: false,
              success: function(resp) {             
              },
              error: function(error) {
                toaster.error(error.responseText);
              }
            });
          });
form.trigger('submit');

this creates multiple(three in my case) toasters. and every subsequent error will just double the number of toasters. if I pass the url and type as form.attr() the error: block code does not get represented on the screen. How do I display the toaster on the screen or make the ajax call execute once? I am not using anchor element to download because it is causing some other problems. so using form.

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