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

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