title: send_from_directory function is being called multiple times for no reason
body: <p>I'm trying to count the number of downloads for each click, but the problem is when i click once the serve is being called multiple times like this:</p>
  
  <pre><code>new_downloads: 15
  127.0.0.1 - - [28/Jun/2019 17:30:46] "GET /document/down?document_id=7d94092899ae11e9b3b1f4b7e27c0e4a&amp;document_title=03.%20Indexation%20-%20suite.pdf HTTP/1.1" 200 -
  new_downloads: 16
  new_downloads: 17
  127.0.0.1 - - [28/Jun/2019 17:30:46] "GET /document/down?document_id=7d94092899ae11e9b3b1f4b7e27c0e4a&amp;document_title=03.%20Indexation%20-%20suite.pdf HTTP/1.1" 200 -
  127.0.0.1 - - [28/Jun/2019 17:30:47] "GET /document/down?document_id=7d94092899ae11e9b3b1f4b7e27c0e4a&amp;document_title=03.%20Indexation%20-%20suite.pdf HTTP/1.1" 206 -
  new_downloads: 18
  new_downloads: 18
  new_downloads: 18
  new_downloads: 18
  127.0.0.1 - - [28/Jun/2019 17:30:48] "GET /document/down?document_id=7d94092899ae11e9b3b1f4b7e27c0e4a&amp;document_title=03.%20Indexation%20-%20suite.pdf HTTP/1.1" 206 -
  127.0.0.1 - - [28/Jun/2019 17:30:48] "GET /document/down?document_id=7d94092899ae11e9b3b1f4b7e27c0e4a&amp;document_title=03.%20Indexation%20-%20suite.pdf HTTP/1.1" 206 -
  127.0.0.1 - - [28/Jun/2019 17:30:48] "GET /document/down?document_id=7d94092899ae11e9b3b1f4b7e27c0e4a&amp;document_title=03.%20Indexation%20-%20suite.pdf HTTP/1.1" 206 -
  127.0.0.1 - - [28/Jun/2019 17:30:48] "GET /document/down?document_id=7d94092899ae11e9b3b1f4b7e27c0e4a&amp;document_title=03.%20Indexation%20-%20suite.pdf HTTP/1.1" 206 -
  </code></pre>
  
  <p>and this this my function in flask:</p>
  
  <pre><code>@app.route('/document/down')
  def down_document():
      executed = False
      document_id = request.args.get('document_id')
      document_title = request.args.get('document_title')
      directory = os.path.dirname(app.instance_path) + "\\corpus" + "\\" + document_id
  
      # resp = make_response(send_file(path, as_attachment=True))
      resp = make_response(send_from_directory(directory=directory, filename=document_title))
      if resp:
          executed = True
  
      if executed:
          old_downloads = Helper.get_num_downloads(document_id)
          new_downloads = old_downloads + 1
          print("new_downloads: " + str(new_downloads))
          Helper.refresh_downloads(document_id=document_id, new_downloads=new_downloads)
          if request.args.get('username'):
              Helper.add_relationship_user_download_doc(username=request.args.get('username'), document_id=document_id)
  
      resp.headers['Access-Control-Allow-Origin'] = '*'
      resp.headers['Content-Type'] = 'application/force-download'
      resp.headers['Content-type'] = 'application/pdf'
      resp.headers['Content-Description'] = 'File Download'
      resp.headers['Content-Disposition'] = 'attachment'
      resp.headers['Content-Transfer-Encoding'] = 'binary'
      resp.headers['Expires'] = 'must-revalidate, post-check=0, pre-check=0'
      resp.headers['Pragma'] = 'public'
      return resp
  </code></pre>
  
  <p>When i remove the function send_from_directory, the api is called once but one i add it the api will be called multiple times.</p>
  
  <p>This is my ajax</p>
  
  <pre><code>$.ajax({
                  url: "http://127.0.0.1:5000/document/down",
                  type: "GET",
                  crossDomain: true,
                  dataType: 'binary',
                  data: {
                      "document_id": document_id,
                      "document_title": filename,
                  },
                  success: function (response) {
                      console.log("success download");
                      Swal.close();
                  },
                  failure: function (request) {
                      alert(request);
                  },
                  error: function (jqXHR, exception) {
                      console.log("error download");
                      let msg = '';
                      if (jqXHR.status === 0) {
                          msg = 'Not connect.\n Verify Network.';
                      } else if (jqXHR.status === 404) {
                          msg = 'Requested page not found. [404]';
                      } else if (jqXHR.status === 500) {
                          msg = 'Internal Server Error [500].';
                      } else if (exception === 'parsererror') {
                          msg = 'Requested JSON parse failed.';
                      } else if (exception === 'timeout') {
                          msg = 'Time out error.';
                      } else if (exception === 'abort') {
                          msg = 'Ajax request aborted.';
                      } else {
                          msg = 'Uncaught Error.\n' + jqXHR.responseText;
                      }
                      alert(msg)
                  }
              });
  </code></pre>