title: JavaScript: function not working without alert()
body: <p><a href="https://stackoverflow.com/questions/11309802/javascript-only-works-if-i-do-an-alert">Possible solution</a></p>
  
  <p>Hello, fellow programmers!</p>
  
  <p>I am writing to you in order to request some help with an issue I recently experienced. The very issue is as follows:</p>
  
  <p>1) I have an ajax request, implemented with jQuery.</p>
  
  <p>2) After returning a successful response, the script should reload the page with the respective changes and if there are any validation errors, insert them after a hidden field, used to store non-critical miscellaneous data. If there are any validation errors, the changes are not saved and the page is just reloaded with the validation error messages. The validation itself is taken care of by a servlet. </p>
  
  <p>3) I noticed that everything works fine, when any kind of alert() is presented before the actual appending of the error messages, but I do not want to have such an alert.</p>
  
  <p>Here is the JavaScript code:</p>
  
  <pre><code>$('#randomFormElement').submit(function() {
          $(this).ajaxSubmit({
              success: function (data, status) {
                  randomFunctionToReloadThePage(arg1, arg2, arg3);
                  var errors = $(data).find('.classNameOfTheErrors').xml();
                  //alert(something);
                  $(errors).insertAfter('#idOfTheHiddenField');
              },
              error: function (jqXHR, textStatus, thrownError) {
              //Error handling if the ajax response fails.
              }
           });
  });
  </code></pre>
  
  <p>So, the main question is: what's the deal with alert() making it work?</p>
  
  <p>==========================</p>
  
  <p>On Chrome, it doesn't work either way.</p>
  
  <p>On FF, it does work only when some alert() is present.</p>
  
  <p>Thanks in advance!</p>