title: jQuery AJAX call works if and only if debugging in FF/Chrome
body: <p>I'm facing a strange issue with a Flask single app and a jQuery AJAX call I'm making via a form in the view. Basically, the endpoint (/register) is called correctly when I debug the JS code, but when I try to run normally, the endpoint is never called, I can see in the Network view that the request is sent, but it seems that it never reaches Flask.</p>
  
  <p>That said, this is my html code (the relevant parts concerning the form and the JS code):</p>
  
  <pre><code>&lt;form action="" method="" id="newsletter-form" role="form"&gt;
      &lt;div class="input-group"&gt;
          &lt;input type="email" name="user_email" class="newsletter-email form-control" placeholder="ENTER EMAIL ADDRESS"&gt;
          &lt;span class="input-group-btn"&gt;
              &lt;button value="" type="submit" class="btn btn-green waves-effect waves-light newsletter-submit"&gt;Get More Info&lt;/button&gt;
          &lt;/span&gt;
      &lt;/div&gt;
      &lt;div id="ajax-panel"&gt;&lt;/div&gt;                               
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is the JS code, based on this <a href="https://stackoverflow.com/a/6203142/526801">SO answer</a>, I've added the event.preventDefault() stuff:</p>
  
  <pre><code>function makeRequest(event){
          event.preventDefault(); //stop the form from being submitted
  
          $.getJSON($SCRIPT_ROOT + '/register', {
                      user_email: $('input[name="user_email"]').val()
                    },
                  function(data) {
                          $('#ajax-panel').empty();
                              if (data.status == 'OK'){
                                  $('#ajax-panel').append('&lt;div class="success"&gt;&lt;strong&gt;' + data.message + '&lt;/div&gt;');
                              }
                              else{
                                  $('#ajax-panel').append('&lt;div class="error"&gt;&lt;strong&gt;' + data.message + '&lt;/div&gt;');
                              }
                  });
          return false;
      }
  
      $('#newsletter-form').submit(function(event){
          makeRequest(event);
      });
  </code></pre>
  
  <p>And here is the Flask code for that endpoint:</p>
  
  <pre><code>@app.route('/register', methods=['GET', 'POST'])
  def register():
      error = None
      user_email = request.args.get('user_email', 0, type=str)
  
      try:
          form = RegisterForm(email=user_email)
          if form.email.data and valid_mail(form.email.data):
              from models import RegisteredMail
              new_rm = RegisteredMail(
                  form.email.data,
                  datetime.datetime.utcnow(),
              )
              try:
                  db.session.add(new_rm)
                  db.session.commit()
                  message = 'Thanks for subscribing, we will keep you posted!'
                  return json.dumps({'status': 'OK', 'message': message})
              except IntegrityError:
                  message = 'Provided email is already used, please use a different one'
                  return json.dumps({'status': 'ERROR', 'message': message})
          else:
              message = 'Provided email is invalid, please use a different one'
              return json.dumps({'status': 'ERROR', 'message': message})
      except Exception as e:
          print e
          return render_template('index.html')
  </code></pre>
  
  <p>As I said, this works perfectly fine if I debug, but when running it does not...I'm scracthing my head here. It looks like if the request never reaches the server, because if I CTRL-C the server, I get the error in JS side, which looks like something is "blocking" the form submission...any clues?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've found the issue, and it had nothing to do with a wrong request or any on the server side...</p>
  
  <p>I had a video tag that was used to stream a video that I had stored in my static/video folder, about 50MB size. Well, I started to comment out big chunks of the view code doing trial &amp; error stuff. It looks that that piece of code was the one causing trouble...</p>
  
  <pre><code>&lt;video class="img_responsive" controls&gt;
      &lt;source src="{{ url_for('static', filename='video/movie.mp4') }}" type="video/mp4"&gt;
      Your browser does not support the video tag.
  &lt;/video&gt;
  </code></pre>
  
  <p>I'm still not 100% sure, but I was getting random exceptions using the above code:</p>
  
  <pre><code>Traceback (most recent call last): 
  File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock self.process_request(request, client_address) 
  File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request self.finish_request(request, client_address) 
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request self.RequestHandlerClass(request, client_address, self) 
  File "/usr/lib/python2.7/SocketServer.py", line 657, in init self.finish() 
  File "/usr/lib/python2.7/SocketServer.py", line 711, in finish self.wfile.flush() 
  File "/usr/lib/python2.7/SocketServer.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size])
  </code></pre>
  
  <p>I really have no clue why this is happening, I've changed to dropbox to act as CDN streaming server for that video and eveything goes great...if anyone has an explanation for this, I'd like to hear it :), otherwise this goes to the X-Files section.</p>