title: AngularJS - File Download through AJAX
body: <p>I created an angular js program for downloading a file from the server here follows the code</p>
  
  <p><strong>HTML Code</strong></p>
  
  <pre><code>&lt;a download="fullList.csv" ng-href="{{ fullListUrl }}" type="button" class="btn btn-success btn-xs exec-batch"  ng-click="exportCSVBulk(batchExec)"&gt;
            &lt;span class="glyphicon glyphicon-ok"&gt;&lt;/span&gt; EXPORT AS CSV
  &lt;/a&gt;
  </code></pre>
  
  <p><strong>AngularJS Controller</strong></p>
  
  <pre><code>$scope.exportCSVBulk=function(){
   var page = "../importExportService/exportBulkCSV/"+batchExec.id;
   $http.get(page).success(function(response) {
   $scope.fullListUrl = 'data:text/csv;charset=utf-8,' + escape(response); 
  });
  }
  </code></pre>
  
  <p>Here what i am doing is when a user click on the <code>EXPORT AS CSV</code> link the function <code>exportCSVBulk</code> fires and from that function the url value (fullListUrl) sets. But this is an ajax request, so when a user click on the link the url, the response time become little bit long which results the url will not redirected properly. Is it possible to fix this problem? or is there is any alternative way to fix this?</p>