title: How to download a csv file requested through jquery/ajax from flask server
body: <p>I am building a python flask web app. I am trying to get a CSV file downloaded through jquery/ ajax call.</p>
  
  <p>This is how my ajax request looks like:</p>
  
  <pre><code>$(".download-btn").on("click", function(){
      $.ajax({
          type: 'GET',
          url: '/downloadFile',
          contentType: 'csv',
          cache: false,
          processData: false,
          async: false,
          success: function(data) {
              console.log("coming");
          },
      });
  </code></pre>
  
  <p>and this is by server code looks like:</p>
  
  <pre><code>app = Flask(__name__)
  path = os.getcwd()
  
  @app.route('/downloadFile',methods = ['GET'])
  def download():
      logger.info('Checking file to download..')
      logger.info(path)
      return send_file(path+"/Generated/modified_file.csv",
                          mimetype='text/csv',
                          attachment_filename='modified_file.csv',
                          as_attachment=True)
  </code></pre>
  
  <p>For your information, "modifed_file.csv" is present inside the path specified before the request is being made.</p>
  
  <p>While running the code I can see </p>
  
  <p>"Checking file to download.." and "coming" in output. But the file is not getting downloaded.</p>
  
  <p>Also if I do </p>
  
  <pre><code>console.log(data);
  </code></pre>
  
  <p>I can see the content of the file.</p>
  
  <p>I am stuck. Any help is appreciated.</p>